Skip to content

Commit

Permalink
Fix compatibility with AR 3.0.3. Closes norman#92
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed Nov 22, 2010
1 parent 2f3f5e5 commit 88f4a97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -6,6 +6,10 @@ suggestions, ideas and improvements to FriendlyId.
* Table of Contents
{:toc}

## 3.1.8 (2010-11-22)

* Fix compatibility with Active Record 3.0.3.

## 3.1.7 (2010-09-22)

* Reserved words can now be regular expressions.
Expand Down
11 changes: 8 additions & 3 deletions lib/friendly_id/active_record_adapter/relation.rb
Expand Up @@ -84,7 +84,7 @@ def friendly_records(friendly_ids, unfriendly_ids)
return find_some_using_slug(friendly_ids, unfriendly_ids) if use_slugs_table
column = fc.cache_column || fc.column
friendly = arel_table[column].in(friendly_ids)
unfriendly = arel_table[relation.primary_key].in unfriendly_ids
unfriendly = arel_table[relation.primary_key.name].in unfriendly_ids
if friendly_ids.present? && unfriendly_ids.present?
where(friendly.or(unfriendly))
else
Expand All @@ -94,7 +94,7 @@ def friendly_records(friendly_ids, unfriendly_ids)

def find_some_using_slug(friendly_ids, unfriendly_ids)
ids = [unfriendly_ids + sluggable_ids_for(friendly_ids)].flatten.uniq
where(arel_table[relation.primary_key].in(ids))
where(arel_table[relation.primary_key.name].in(ids))
end

def sluggable_ids_for(ids)
Expand Down Expand Up @@ -166,7 +166,12 @@ def find_one(id)

def find_some(ids)
return super unless klass.uses_friendly_id?
Find.new(self, ids).find_some or super
Find.new(self, ids).find_some or begin
# A change in Arel 2.0.x causes find_some to fail with arrays of instances; not sure why.
# This is an emergency, temporary fix.
ids = ids.map {|id| (id.respond_to?(:friendly_id_config) ? id.id : id).to_i}
super
end
rescue ActiveRecord::RecordNotFound => error
find ? find.raise_error(error) : raise(error)
end
Expand Down

0 comments on commit 88f4a97

Please sign in to comment.