should I do polimorphism or one-to-many in Laravel/Eloquent
up vote
-1
down vote
favorite
I'm designing an application, and have doubts about to proceed. I'm avoiding the use of STI; so here are my questions.
I have a table person (Parent) which can be (children) a borrower, investor or owner; so a person would can one or all three; meaning that an investor can take out a loan, and the owner can invest money via CDs...
When designing the objects, they all inherit from a person; however, the logical thing to do is create a table for each child with a Person ID. But reading online looks like the correct way to do it is with polymorphism and create a type_id and id_of_type field.
Am I missing something? Which approach works better? I also have more parts of the project where I'mimplemeting this,
Option 1:
enter image description here
Option 2:
enter image description here
php database laravel eloquent
add a comment |
up vote
-1
down vote
favorite
I'm designing an application, and have doubts about to proceed. I'm avoiding the use of STI; so here are my questions.
I have a table person (Parent) which can be (children) a borrower, investor or owner; so a person would can one or all three; meaning that an investor can take out a loan, and the owner can invest money via CDs...
When designing the objects, they all inherit from a person; however, the logical thing to do is create a table for each child with a Person ID. But reading online looks like the correct way to do it is with polymorphism and create a type_id and id_of_type field.
Am I missing something? Which approach works better? I also have more parts of the project where I'mimplemeting this,
Option 1:
enter image description here
Option 2:
enter image description here
php database laravel eloquent
Did you refer Laravel Documentation? laravel.com/docs/5.7/eloquent-relationships
– Igor Carvalho
Nov 11 at 4:31
Yes, the question is not about how but rather which one makes more sense. Should I adopt polymorphism or can I just say that investor belongs to person while person has many investor.
– vdavidguerrero
Nov 11 at 4:37
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm designing an application, and have doubts about to proceed. I'm avoiding the use of STI; so here are my questions.
I have a table person (Parent) which can be (children) a borrower, investor or owner; so a person would can one or all three; meaning that an investor can take out a loan, and the owner can invest money via CDs...
When designing the objects, they all inherit from a person; however, the logical thing to do is create a table for each child with a Person ID. But reading online looks like the correct way to do it is with polymorphism and create a type_id and id_of_type field.
Am I missing something? Which approach works better? I also have more parts of the project where I'mimplemeting this,
Option 1:
enter image description here
Option 2:
enter image description here
php database laravel eloquent
I'm designing an application, and have doubts about to proceed. I'm avoiding the use of STI; so here are my questions.
I have a table person (Parent) which can be (children) a borrower, investor or owner; so a person would can one or all three; meaning that an investor can take out a loan, and the owner can invest money via CDs...
When designing the objects, they all inherit from a person; however, the logical thing to do is create a table for each child with a Person ID. But reading online looks like the correct way to do it is with polymorphism and create a type_id and id_of_type field.
Am I missing something? Which approach works better? I also have more parts of the project where I'mimplemeting this,
Option 1:
enter image description here
Option 2:
enter image description here
php database laravel eloquent
php database laravel eloquent
asked Nov 11 at 4:21
vdavidguerrero
11
11
Did you refer Laravel Documentation? laravel.com/docs/5.7/eloquent-relationships
– Igor Carvalho
Nov 11 at 4:31
Yes, the question is not about how but rather which one makes more sense. Should I adopt polymorphism or can I just say that investor belongs to person while person has many investor.
– vdavidguerrero
Nov 11 at 4:37
add a comment |
Did you refer Laravel Documentation? laravel.com/docs/5.7/eloquent-relationships
– Igor Carvalho
Nov 11 at 4:31
Yes, the question is not about how but rather which one makes more sense. Should I adopt polymorphism or can I just say that investor belongs to person while person has many investor.
– vdavidguerrero
Nov 11 at 4:37
Did you refer Laravel Documentation? laravel.com/docs/5.7/eloquent-relationships
– Igor Carvalho
Nov 11 at 4:31
Did you refer Laravel Documentation? laravel.com/docs/5.7/eloquent-relationships
– Igor Carvalho
Nov 11 at 4:31
Yes, the question is not about how but rather which one makes more sense. Should I adopt polymorphism or can I just say that investor belongs to person while person has many investor.
– vdavidguerrero
Nov 11 at 4:37
Yes, the question is not about how but rather which one makes more sense. Should I adopt polymorphism or can I just say that investor belongs to person while person has many investor.
– vdavidguerrero
Nov 11 at 4:37
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245806%2fshould-i-do-polimorphism-or-one-to-many-in-laravel-eloquent%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you refer Laravel Documentation? laravel.com/docs/5.7/eloquent-relationships
– Igor Carvalho
Nov 11 at 4:31
Yes, the question is not about how but rather which one makes more sense. Should I adopt polymorphism or can I just say that investor belongs to person while person has many investor.
– vdavidguerrero
Nov 11 at 4:37