2010-05-05 4 views
1

has_many_polymorphs에 문제가 있습니다. 어쩌면 저를 도울 수 있습니다. has_many_polymorphs problem

나는 내가 로그에

>> i = Issue.first 
+----+--------+---------+----------+---------------+----------------+-------------+-------------+-----------------+---------------------------+---------------------------+ 
| id | closed | user_id | answered | answers_count | comments_count | views_count | flags_count | favorites_count | created_at    | updated_at    | 
+----+--------+---------+----------+---------------+----------------+-------------+-------------+-----------------+---------------------------+---------------------------+ 
| 1 | false | 2  |   | 2    | 2    | 0   | 0   | 0    | 2010-04-22 00:14:56 +0400 | 2010-05-01 02:35:30 +0400 | 
+----+--------+---------+----------+---------------+----------------+-------------+-------------+-----------------+---------------------------+---------------------------+ 
1 row in set 
>> i.applications 
ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not find the source association(s) :application in model Relation. Try 'has_many :applications, :through => :relation, :source => <name>'. Is it one of :content or :thing? 
     from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/reflection.rb:289:in `check_validity!' 
     from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/has_many_through_association.rb:5:in `initialize' 
     from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1300:in `new' 
     from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations.rb:1300:in `applications' 
     from (irb):2 
     from :0 
>> 

다음을 참조 일부 모델

class Issue < ActiveRecord::Base 
    has_many_polymorphs :things, :from => [:applications], :through => :relations 
ene 

class NewsArticle < ActiveRecord::Base 
    has_many_polymorphs :things, :from => [:applications], :through => :relations 
end 

class Application < ActiveRecord::Base 
    has_many_polymorphs :contents, :from => [:news_articles, :issues], :through => :relations 
end 

class Relation < ActiveRecord::Base 
    belongs_to :content, :polymorphic => true 
    belongs_to :thing, :polymorphic => true 

    acts_as_double_polymorphic_join(
    :contents => [:news_articles, :issues], 
    :things => [:applications] 
) 
end 

하지만 일부 문제에 대한 응용 프로그램을 얻을 시도에서 내가
** has_many_polymorphs: autoload hook invoked 
** has_many_polymorphs: preloading parent model Application 
** has_many_polymorphs: preloading parent model Issue 
** has_many_polymorphs: preloading parent model NewsArticle 
** has_many_polymorphs: preloading parent model Relation 
** has_many_polymorphs: autoload hook invoked 
** has_many_polymorphs: preloading parent model Application 
** has_many_polymorphs: preloading parent model Issue 
** has_many_polymorphs: preloading parent model NewsArticle 
** has_many_polymorphs: preloading parent model Relation 
    Issue Load (0.9ms) SELECT * FROM "issues" LIMIT 1 

어떻게 그것을 해결하기 위해 볼 수 있나요?

PS : 레일 2.3.5, PostgreSQL을

+0

관계에 관한 내용을 포함하지 말아야합니까? –

+0

>> i.things Hirb 오류 : PGError : 오류 : 열 관계 .issue_id가 존재하지 않습니다. LINE 1 : ... FROM relations JOIN이 polymorphic_parent 관련 문제를 토론합니다 .... –

답변

2

나는이 문제를 한 적이 :) 문제는 - (- 문제, NewsArticle, 응용 프로그램이 문제에서)해야 그 문서, 정보를 포함하지 않는 연결 모델이 (예 : has_many_polymorphs : things, : from => [: applications], : through => : relation)