mercredi 21 janvier 2015

Sqlite given no such column error in polymorphic has many through

I'm not sure if it's an error with sqlite, but I had this working in other projects and now I'm getting an error, the scenario is the following. I hava a categories table, with the following model:



class Category < ActiveRecord::Base
has_many :tags
end


An Tags table with the following model:



class Tag < ActiveRecord::Base
belongs_to :categorizable, polymorphic: true
belongs_to :category
end


And a Question model one of the multiple models that can be categorizable through the polymorphic association:



class Question < ActiveRecord::Base
has_many :tags, as: :categoryzable
has_many :categories, through: :tags
end


Using the rails console I can create Tags and get the categorizable object (in this case a Question):


But when trying to obtain the tags or the categories for a given Question, i'm getting the following error:



ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: tags.categoryzable_id: SELECT "tags".* FROM "tags" WHERE "tags"."categoryzable_id" = ? AND "tags"."categoryzable_type" = ?


My db/schema.rb file shows both the categorizable_id and categorizable_type columns for the tags table, so my question is why is sqlite not finding them?


Aucun commentaire:

Enregistrer un commentaire