Reputation: 1514
The code below worked fine in Rails 3 but it throws an error:
ActiveRecord::StatementInvalid: SQLite3::SQLException: ambiguous column name:
id: SELECT "categories".id FROM "categories"
INNER JOIN "categorizations"
ON "categories"."id" = "categorizations"."category_id"
WHERE "categorizations"."reason_id" = 283 ORDER BY id
The problems seems to be the call to reason.category_ids
- reasons.each do |reason|
- cat_ids = reason.category_ids.map {|id| "cat_id_#{id}"}.join(" ")
%li{"data-reason-id" => reason.id, :class => cat_ids}
%a= reason.text
class Reason < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
UPDATE: When commenting out the last line here the problem is fixed. is it a bug?
class Category < ActiveRecord::Base
has_many :categorizations
has_many :reasons, :through => :categorizations
scope :active, where("active = ?", true)
default_scope :order => 'id'
Upvotes: 0
Views: 1601
Reputation: 7111
Here we go...
[In Rails 3.1] Supplying options hash to with_scope, with_exclusive_scope and default_scope has also been deprecated:
default_scope :order => "id DESC"
Try:
default_scope order('categories.id')
Upvotes: 4