Oluşturma oluşturma modellerinde çalışmak için inverse_of
alamıyorum. Bunun bir hata mı, yoksa böyle uygulanmadığından emin değilim.ActiveRecord: inverse_of has_many üzerinde çalışmaz: oluşturma modelinde aracılığıyla oluşturma
class Challenge < ActiveRecord::Base
has_many :groups, :through => :group_challenges
has_many :group_challenges, :inverse_of => :challenge
attr_accessor :contact_ids
end
class GroupChallenge < ActiveRecord::Base
belongs_to :challenge, :inverse_of => :group_challenges
belongs_to :group, :inverse_of => :group_challenges
before_save :check_challenge
def check_challenge
Rails.logger.debug("challenge.contact_ids: #{challenge.contact_ids}")
end
end
class Group < ActiveRecord::Base
has_many :challenges, :through => :group_challenges
has_many :group_challenges, :inverse_of => :group
end
contact_ids
benim challenge
sanal bir niteliktir ve bunu dernek oluşturulduğunda group_challenges
modelinde bu erişmek istediğiniz: Aşağıdaki modelleri var. İşe yaratamıyorum. İşte bir örnek:
challenge = Challenge.new :groups => Group.all, :contact_ids => [1,2,3]
# log output => challenge.contact_ids: []
Ancak inverse_of
yapar modelleri yeniden yüklenir eser
challenge.reload
challenge.group_challenges.first.challenge.contact_ids
# log output => challenge.contact_ids: [1,2,3]
bu uygulamada inverse_of sadece bir tasarım sınırlaması ya da daha doğrusu bir hata olup olmadığını
bilen var mı ? gereğince
Aynı sorunu yaşıyorum. – rafamvc