In this case I believe you should use hasOne instead.
BelongsTo is mostly used together with hasMany, example a folder that has many files, and each file belongs to a folder.
In this case you would use hasOne
/hasMany
, since the foreign key is on the other table of this relationship.
belongsTo
will be on the other model (Category
and Brand
), unless you swap the FK.
However you should check http://laravel.com/docs/4.2/eloquent#polymorphic-relations, it might be the way to go if you find it nice and easy.
If i use hasOne, eloquent told me that i does not find the category_id field in Picture table.
My DB is like this :
It works with belongsTo but not with hasOne.
Yes, this is what you need. It's in my post, which was an answer to the previous by @mengidd - didn't mention that ;)
But check the polymorphic relations.
Ok, i see what you mean :) thanks, and yes, i'll check polymorphic !
Thanks again
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community