二级模型

时间:2016-04-05 18:02:03

标签: ruby-on-rails ruby-on-rails-4

我有地点,订单和事件模型。

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

0 个答案:

没有答案