我有地点,订单和事件模型。
class Order < ActiveRecord::Base
belongs_to :event
validates :first_name, presence: true
validates :last_name, presence: true
validates :amount, presence: true, :numericality => {:only_integer=>true, :greater_than =>0}
end
class Event < ActiveRecord::Base
belongs_to :location
validates :title, presence: true
validates :price, presence: true, :numericality => {:greater_than =>0}
end
class Location < ActiveRecord::Base
has_many :events, dependent: :destroy
has_many :orders, through: :events
validates :title, presence: true
validates :size, presence: true, :numericality => {:only_integer=>true,:greater_than =>0}
end
我想在订单create
控制器中检查该位置有多少座位。
@orders.events
会给我正确的回复。
如果我要求@order.event.location
,则返回始终为"#"
。
这是安全问题吗?我还添加了Location
模型:
has_many: orders, through: events