php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

Join returns list (instead of object) on 1-to-1 relationship

Open nik2208 opened this issue 3 years ago • 4 comments
trafficstars

join returns a subobject array even if it has a 1 to 1 relationship

not really a problem.. just not to access the object using its index [0]

nik2208 avatar Sep 07 '22 10:09 nik2208

How would one differentiate a 1 to 1 relationship from a 1 to many relationship in SQL? Can you share your table create script for two tables with a 1 to 1 relationship?

mevdschee avatar Sep 08 '22 07:09 mevdschee

well.. most of the times I try to find myself around..maybe I'm missing something.. but if u set the foreign key as unique key you get a 1 to 1 relationship.. am I wrong?

nik2208 avatar Sep 08 '22 07:09 nik2208

am I wrong?

No.. you aren't, it is a great suggestion. I guess I could try to detect the combination of a FK and a unique constraint. I'll turn this into an enhancement.

mevdschee avatar Sep 08 '22 09:09 mevdschee

There may be a problem of a table having two 1-on-1 relationships with another table, but that is an edge case and may be solved with some form of aliasing.

mevdschee avatar Sep 08 '22 09:09 mevdschee