Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overridden finders are not work properly with history for ActiveRecord::Associations #489

Closed
palexvs opened this issue Nov 19, 2013 · 5 comments

Comments

@palexvs
Copy link

palexvs commented Nov 19, 2013

rails (4.0.1)
friendly_id (5.0.1)

class Sites
  friendly_id :name, use: [:finders, :slugged, :history], slug_column: :cached_slug
end

it works properly for class:

> Site.find('name2')
SELECT `sites`.* FROM `sites` INNER JOIN `friendly_id_slugs` ON `friendly_id_slugs`.`sluggable_id` = `sites`.`id` AND `friendly_id_slugs`.`sluggable_type` = 'Site' WHERE (`friendly_id_slugs`.`sluggable_type` = 'Site' AND `friendly_id_slugs`.`slug` = 'name2') ORDER BY `sites`.`id` ASC LIMIT 1

but not for ActiveRecord::Associations:

> User.first.sites.find('name2')
SELECT `sites`.* FROM `sites` WHERE `sites`.`user_id` = 7664 AND `sites`.`cached_slug` = 'name2' ORDER BY `sites`.`id` ASC LIMIT 1
ActiveRecord::RecordNotFound: ActiveRecord::RecordNotFound
@acarr468
Copy link

I'm having problems very similar to this as well, any assistance would be much appreciated.

@norman
Copy link
Owner

norman commented Dec 18, 2013

I'm looking into this. As a workaround in the mean time try using the friendly scope on the association, e.g., User.first.sites.friendy.find('name2').

@acarr468
Copy link

I get the same result both with and without the friendly scope. I do have the :finders addon running as well.

@jgadbois
Copy link
Contributor

I'm also seeing this. The problem seems to be that if [:history] is turned on, then friendly_id looks in the slugs table, without ever looking at the slug_column. However the previous version of the gem does not always put an entry in that table it seems like.

@jgadbois
Copy link
Contributor

This seems to fix the problem, and tests still all pass. Not sure of all the implications however:

#509

@norman norman closed this as completed May 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants