【发布时间】:2014-12-13 13:27:01
【问题描述】:
我有 3 张桌子,汽车、公寓和商店。每张桌子都有照片。照片存储在数据库中。我只想为照片使用一张表,我不想为每个 Cars、Flats 和 Shops 创建 Photos 表。
照片表结构是这样的;
| id | photo_url | type | destination_id |
------------------------------------------------------------
1 | http://example.com/1.jpg | Cars | 1 |
2 | http://example.com/2.jpg | Flats | 1 |
3 | http://example.com/3.jpg | Flats | 2 |
4 | http://example.com/4.jpg | Shops | 1 |
5 | http://example.com/3.jpg | Shops | 2 |
我需要在 Shops、Flats 和 Cars 模型类中定义 hasMany 与类型的关系。
这样做的正确方法是什么?
【问题讨论】:
标签: laravel orm laravel-4 eloquent