From e263f74e446c1e4d95901e9e8d7d6713c078c38e Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Wed, 11 Aug 2010 14:55:41 -0300 Subject: [PATCH] Revert back to `join` rather than `include`. AR2's `join` will make the found model instance read-only, hence the previous change to use `include`. However, `include` will add columns from the slug table to the query, so queries that use unqualified column names and work without FriendlyId, will fail when FriendlyId is used if a column name from the slug table is used in a scope or find conditions. This change simply sets the `:readonly` option to `false` unless it is explicitly set to something truthy. This doesn't feel entirely right but in practice ends up working better. closes #75 --- lib/friendly_id/active_record_adapter/finders.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/friendly_id/active_record_adapter/finders.rb b/lib/friendly_id/active_record_adapter/finders.rb index 6e1785501..3153cc2b0 100644 --- a/lib/friendly_id/active_record_adapter/finders.rb +++ b/lib/friendly_id/active_record_adapter/finders.rb @@ -36,11 +36,12 @@ def find_some parse_ids! scope = some_friendly_scope if use_slugs? && @friendly_ids.present? - scope = scope.scoped(:include => :slugs) + scope = scope.scoped(:joins => :slugs) if fc.scope? scope = scope.scoped(:conditions => {:slugs => {:scope => scope_val}}) end end + options[:readonly] = false unless options[:readonly] @result = scope.all(options).uniq validate_expected_size! @result.each { |record| record.friendly_id_status.name = id } @@ -62,8 +63,9 @@ def find_one_using_cached_slug def find_one_using_slug name, seq = id.to_s.parse_friendly_id - scope = scoped(:include => :slugs, :conditions => {:slugs => {:name => name, :sequence => seq}}) + scope = scoped(:joins => :slugs, :conditions => {:slugs => {:name => name, :sequence => seq}}) scope = scope.scoped(:conditions => {:slugs => {:scope => scope_val}}) if fc.scope? + options[:readonly] = false unless options[:readonly] @result = scope.first(options) assign_status end