我有这些关系:
class User
include Mongoid::Document
has_many :orders, :class_name => 'Order', :inverse_of => :user
has_many :sold_orders, :class_name => 'Order', :inverse_of => :seller
end
class Order
include Mongoid::Document
belongs_to :user, :class_name => 'User', :inverse_of => :orders
belongs_to :seller, :class_name => 'User', :inverse_of => :sold_orders
end
如果我想获得当前卖家的所有订单,我会在控制器中运行,例如:
def jobs
@orders = Order.where(seller: current_user)
p @orders
respond_to do |format|
format.html { render :layout => 'centered'}
end
end
我可以在我的日志控制台中看到:
#<Mongoid::Criteria
selector: {:seller=>#<User _id: 500541f81d41c82f1b000037, _type: "User", created_at: 2012-07-17 10:44:08 UTC, ....more attributes>},
options: {},
class: Order,
embedded: false>
这是错误的,因为我有一个用户,但我想获得当前卖家的所有订单。
如何获取当前卖家的所有订单?
谢谢!