Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在RoR中显示1对多和多对1关系?_Ruby On Rails_Ruby_Entity Relationship - Fatal编程技术网

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