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










share|improve this question





















  • 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














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










share|improve this question





















  • 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












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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto