Hi,
I know a very, very similar question has been asked before. The hackish solution to that question doesn't work if I want to chain in more scopes, so I'm asking again here, with a bit more information as to where the issue is coming from.
# Relevant code only...
class Publication < ActiveRecord::Base
has_many :issues
has_many :articles, :through => :issues
end
class Issue < ActiveRecord::Base
belongs_to :publication
has_many :articles
end
class Article < ActiveRecord::Base
belongs_to :issue
define_index do
has issue(:publication_id), :as => :publication_id
end
end
Therefore, I'd expect the following code to work:
Publication.first.articles.search 'foobar'
However, it returns the following error:
RuntimeError: Missing Attribute for Foreign Key publication_id
from /home/matchu/rails/torch/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/active_record/has_many_association.rb:18:in `search'
This seems to imply that the publication_id attribute that I specifically set does not exist. However, it does.
Article.search :with => {:publication_id => 1}
So, I suppose I can just use that syntax, even though it's significantly less pretty. Making this question not particularly urgent. But I definitely am curious as to why this occurs. Any thoughts?