这是我的模型:
class Flight < ActiveRecord::Base
has_many :seats, dependent: :destroy, inverse_of: :flight
end
class Seat < ActiveRecord::Base
belongs_to :flight, inverse_of: :seats
end
看起来inverse_of
效果很好,但是当我使用条件时它不起作用:
f1 = Flight.first
s1 = f1.seats.first
s2 = f1.seats.second
s3 = f1.seats.where(id: 0..1000000).third
s1.flight.equal? s2.flight
=> true
s1.flight.equal? s3.flight
=> false
这是什么解释?我怎样才能使这项工作?