Relation fields assuming foreign key
Opened this issue · 1 comments
jgkinnear commented
The RelationField
is assuming the foreign key is the tablename_id
. Although this is probably most common, its not always the case (as in mine!). This means that any foreign key that does not follow this format will break the query :(
In the HasMnayField
class it does the following
$baseModel = new $baseModel;
$primaryKey = $baseModel->getKeyName();
...
$item->{$primaryKey};
And option would be to use Laravel relation method getPlainForeignKey
$baseModel->{$this->getName()}()->getPlainForeignKey()
I made these changes and the forms display correctly, although I don't have enough time to properly test, hopefully somebody can do this :)
w3z315 commented
+1
I am working on a PR for that and default values for relationships e.g. Not set