Ruby on rails 如何在RoR中显示1对多和多对1关系?
我有一个名为“订单”的表,其中有许多“订单项目”,每个“订单项目”都属于“订单”和“产品”。在数据库中,我有一条顺序记录。记录如下:Ruby on rails 如何在RoR中显示1对多和多对1关系?,ruby-on-rails,ruby,entity-relationship,Ruby On Rails,Ruby,Entity Relationship,我有一个名为“订单”的表,其中有许多“订单项目”,每个“订单项目”都属于“订单”和“产品”。在数据库中,我有一条顺序记录。记录如下: orders table: id = 1 name= customer 订单项目表如下所示: id=1 product_id=233 order_id =1 id=2 product_id=454 order_id =1 我有@orders obj,如何使用订单并查找订单项目和产品信息?您应该能够使用: @orders.order_items 及 查看以下页
orders table: id = 1 name= customer
订单项目表如下所示:
id=1 product_id=233 order_id =1
id=2 product_id=454 order_id =1
我有@orders obj,如何使用订单并查找订单项目和产品信息?您应该能够使用:
@orders.order_items
及
查看以下页面:
…请特别注意第一个介绍部分
@orders.product