有两个表:user
和order
:
create_table "orders" do | t |
t.text "name"
t.integer "user_id"
end
create_table "users" do | t |
t.text "email"
end
两个班:
class Order <ActiveRecord :: Base
belongs_to: users
end
class User <ActiveRecord :: Base
has_many: orders
end
控制器:
class TestController <ApplicationController
def index
@ tmp = Order.all(:include =>:users)
end
end
问题:我需要所有订单,但不是user_id
与email
关联的订单user_id
被退回