activerecord - Rails polymorphic associations - has_many condition error -
i'm using rails 3.2.8 , i'm having troubles polymorphic associations. have model activity polymorphic related polymorphic model contribution can asset_file, biography, dynamic_annotation or citation.
so grandfather activity...the father contribution , sons (of contributions) biographies, asset_file, dynamic_annotations or citations.
i model thing aggregate of concepts have next code:
has_many :activities, :order => 'created_at desc', :dependent =>:delete_all has_many :contributions, :through => :activities, :source => :activable, :source_type => "contribution" has_many :dynamic_annotations, :through => :contributions, :source => :contributable, :source_type => "dynamicannotation", :conditions => {"contributions.c_state" => "accepted"} has_many :biographies, :through => :contributions, :source => :contributable, :source_type => "biography", :conditions => {"contributions.c_state" => "accepted"} has_many :citations, :through => :contributions, :source => :contributable, :source_type => "citation", :conditions => {"contributions.c_state" => "accepted"} has_many :asset_files, :through => :contributions, :source => :contributable, :source_type => "assetfile", :conditions => {"contributions.c_state" => "accepted"}
the problem: opened console , typed next query:
thing.first.biographies
the sql got:
select `biographies`.* `biographies` inner join `contributions` on `biographies`.`id` = `contributions`.`contributable_id` inner join `activities` on `contributions`.`id` = `activities`.`activable_id` `activities`.`thing_id` = 1 , `activities`.`activable_type` = 'contribution' , (`contributions`.`c_state` = 'accepted') , (`contributions`.`contributable_type` = 'biography')
that correct answer
then typed after command:
thing.first.dynamic_annotations
the sql got:
select `dynamic_annotations`.* `dynamic_annotations` inner join `contributions` on `dynamic_annotations`.`id` = `contributions`.`contributable_id` inner join `activities` on `contributions`.`id` = `activities`.`activable_id` `activities`.`thing_id` = 1 , `activities`.`activable_type` = 'contribution' , (`contributions`.`c_state` = 'accepted') , (`contributions`.`contributable_type` = 'biography' , `contributions`.`contributable_type` = 'dynamicannotation')
i got void result because object cannot have 2 types of corse.
if can me apreciate :)
thanks in advance,
i found rails issue: https://github.com/rails/rails/issues/3882 workaround "alarribeau" solve problem. not fix can you.
Comments
Post a Comment