lundi 30 novembre 2015

Laravel how many relationship can be chained

I have a database composed by users, users_child, child.

I create a ONE to MANY relationship between Users and users_child, then i create a relationship between users_child and child. Now the below code work:

    $test = users::find(1)->users_child
    $test1= users_child::find(1)->child

Now i want to know if is possible to create a single row that link the three table like this:

    $test = users::find(1)->users_child->child

I create the relationship in the model but in the db i don't create Foreign Key, it's a problem? on the model i specify the field for link table.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire