krafthaus / bauhaus

Laravel 4 Admin Generator
http://bauhaus.krafthaus.nl/
GNU General Public License v2.0
1 stars 0 forks source link

Relation fields assuming foreign key #50

Open jgkinnear opened 9 years ago

jgkinnear commented 9 years ago

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 9 years ago

+1

I am working on a PR for that and default values for relationships e.g. Not set