Skip to content

Commit

Permalink
Revert back to join rather than include.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
norman committed Aug 11, 2010
1 parent 0804bc4 commit e263f74
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/friendly_id/active_record_adapter/finders.rb
Expand Up @@ -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 }
Expand All @@ -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
Expand Down

0 comments on commit e263f74

Please sign in to comment.