samedi 30 juillet 2016

Is it possible to create custom relationships in Laravel models?

I have a relationship which is neither One-To-One nor One-To-Many and I was wondering if it's possible to express a custom relationship in Laravel/Eloquent models.

Essentially I have products which belong to a single category, but multiple products can belong to the same category. The products table stores the category_id. This obviously isn't One-To-One as categories are reused and Laravel would require a product_id foreign key on the categories table. It is closer to a One-To-Many, which is limited to a single item, but I'd prefer having to avoid making an additional category_product table to define a single relationship. I suspect this is a Many-To-One relationship?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2a7aRpO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire