:inverse_to 不适用于我的复杂案例
class Communication::Message < ActiveRecord::Base
belongs_to :conversation_for_proposal, {
:class_name => 'Communication::Conversation::ForProposal',
:foreign_key => :conversation_id,
:inverse_of => :messages_for_proposal
}
end
class Communication::Conversation::ForProposal < ActiveRecord::Base
has_many :messages_for_proposal, {
:class_name => 'Communication::Message',
:foreign_key => :conversation_id,
:inverse_of => :conversation_for_proposal
}
end
问题:Communication::Conversation::ForProposal 不知道消息
Communication::Conversation::ForProposal.new.messages_for_proposal.build.conversation_for_proposal # => ok
Communication::Message.new.build_conversation_for_proposal.messages_for_proposal # => []
思考:
Communication::Message.reflect_on_association(:conversation_for_proposal).active_record
# => Communication::Message
Communication::Message.reflect_on_association(:conversation_for_proposal).inverse_of.active_record
# => Communication::Conversation::ForProposal
我想念什么?