Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Indexing virtual attributes breaks fuzzy update #20

Closed
airblade opened this issue Sep 30, 2013 · 2 comments
Closed

Indexing virtual attributes breaks fuzzy update #20

airblade opened this issue Sep 30, 2013 · 2 comments

Comments

@airblade
Copy link

The README says:

your searchable fields do not have to be stored, they can be dynamic methods too

I have a class like this:

class Employee < ActiveRecord::Base
  fuzzily_searchable :name
  def name
    "#{first_name} #{last_name}"
  end
end

– where :first_name and :last_name are columns in my employees table.

Fuzzily happily indexes the names and searches them. However any update to a record throws an error because fuzzily's after_save callback executes:

record.send("#{field}_changed?".to_sym)

– and the name_changed? method doesn't exist (and isn't created by active record).

@airblade
Copy link
Author

A workaround is to define that method explicitly:

class Employee < ActiveRecord::Base
  # ...as above...
  def name_changed?
    first_name_changed? || last_name_changed?
  end
end

@mezis
Copy link
Owner

mezis commented Dec 1, 2013

I can't see an obvious way to work around this, so I'll mention it in the README (unless you have suggestions). Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants