我有 3 个模型:
class Request < ActiveRecord::Base
acts_as_paranoid
belongs_to :offer
end
class Offer < ActiveRecord::Base
belongs_to :cruise, inverse_of: :offers
has_many :requests
end
class Travel < ActiveRecord::Base
acts_as_paranoid
has_many :offers, inverse_of: :travel
end
通常我可以Travel
像这样通过链访问对象:request.offer.travel
.
但是,如果Travel
我需要的对象被删除paranoia
- 我无法通过此类对象链访问它。
Travel.with_deleted.find(some_id_of_deleted_travel)
完美地工作,但是request.offers.travel.with_deleted
,同一个物体,把我扔了undefined method 'with_deleted' for nil:NilClass
。
如何通过关系访问已删除的对象?