Sunday, February 6, 2011

[Rails] has_many :through question

Hi,
I am having some difficulty getting has_many relationship setup
correctly.

def acts_as_markable
has_many :marks, :as => :markable
belongs_to :author, :class_name => "WebsiteUser"
end

class Video < ActiveRecord::Base
set_table_name "markables"
acts_as_markable
end

class Mark < ActiveRecord::Base
acts_as_markable
belongs_to :markable, :polymorphic => true
end

class WebsiteUser < ActiveRecord::Base
has_many :marks
has_many :videos_marked, :through => :marks, :source
=> :markable, :source_type => "Video", :class_name =>
"Video", :foreign_key => :author_id
end

running WebsiteUser.first.videos_marked I get this:
SQLite3::SQLException: no such column: marks.website_user_id: SELECT
"markables".* FROM "markables" INNER JOIN "marks" ON "markables".id =
"marks".markable_id AND "marks".markable_type = 'Video' WHERE
(("marks".website_user_id = 1))

Correct query would be:
SELECT "markables".* FROM "markables" INNER JOIN "marks" ON
"markables".id = "marks".markable_id AND "marks".markable_type =
'Video' WHERE (("marks".author_id = 1))

any ideas? thank you.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate