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

association perplexity #44

Open
SNlsn opened this issue Nov 2, 2009 · 1 comment
Open

association perplexity #44

SNlsn opened this issue Nov 2, 2009 · 1 comment

Comments

@SNlsn
Copy link

SNlsn commented Nov 2, 2009

given a model
Company
with attribute
name

and a model
Contact
with attributes
first_name and last_name

The Models are associated like this:
Contact belongs_to Company
Company has_many Contacts

I wish to make a search field into which I can type a portion of either the contact's first name, the contact's last name or the company name.

This works:
@contacts = Contact.company_name_like(params[:search])

This works:
@contacts = Contact.first_name_or_last_name_like(params[:search])

This does NOT work:
@contacts = Contact.company_name_or_first_name_or_last_name_like(params[:search])
It returns this error:
"The condition 'company_name' is not a valid condition, we could not find any scopes that match this."

Evidently the scope company_name works by itself but not in combination with the other two. And the other two work, but not with company_name. I can only assume this has to do with the association and I am missing something obvious. Can anyone point out how to do it correctly?

The last example (company_name_or_first_name_or_last_name_like) worked in an earlier version of my app, when company was an attribute of Contact. When I made Company a separate model it stopped working.

I believe I have the current version of binarylogic-searchlogic. Rails version is 2.3.2, in development mode with standard sqlite database.

Thank you.

@kylewelsby
Copy link

I have the same issue, but no solution yet.

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

2 participants