mysql - Rails 1 to 2 Polymorphic -


i'm having trouble implementing 1-to-2 association, polymorphic. have 3 models involved in this, rule, ip , ipgroup. each rule has 2 of ipish, can either ip or ipgroup. however, when loading entries db, ipish_from , ipish_to remain nil. also, don't confused class_name: "ipish", there no explicit class in project named "ipish"; in older version of project not polymorphic , said class_name: "ip".

class rule   belongs_to :ipish_from, class_name: "ipish", foreign_key: :ipish_id_from, polymorphic: true   belongs_to :ipish_to, class_name: "ipish", foreign_key: :ipish_id_to, polymorphic: true end  class ip   has_and_belongs_to_many :ip_groups   has_many :rules_from, as: :ipish   has_many :rules_to, as: :ipish end  class ipgroup   has_and_belongs_to_many :ips   has_many :rules_from, as: :ipish   has_many :rules_to, as: :ipish end 

the table in mysql-db looks this

++++++++++++++++++++++++++++ + rules                    + ++++++++++++++++++++++++++++ + ipish_id_from: int       + + ipish_type_from: string  + + ipish_id_to: int         + + ipish_type_to: string    + ++++++++++++++++++++++++++++ 

any tips on how should doing this? must use polymorphic associations this. also, problem exist because of how objects related; know how "standard" polymorphism works. maybe rails expects different column name determine type of ipish object? haven't found says how change rails expects, unfortunately.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -