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

find_by not working with multiple fields, only uses the field that was defined first #49

Closed
goalaleo opened this issue Dec 5, 2016 · 3 comments
Assignees
Labels

Comments

@goalaleo
Copy link

goalaleo commented Dec 5, 2016

Relating to this line in README.md:
Foo.find_by(someField: [searchquery1, searchquery2], someOtherField: "bar").load

Querying against multiple fields only uses the field that was defined first:

[56] pry(main)> ContentfulMeal.find_by(day:2, diet_type:"Gluteeniton").load.map{|cm| cm.diet_type}
=> ["Gluteeniton",
 "Normaali",
 "Normaali",
 "Normaali",
 "Gluteeniton",
 "Normaali",
 "Normaali",
 "Normaali",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Normaali",
 "Normaali",
 "Normaali",
 "Normaali",
 "Gluteeniton",
 "Normaali",
 "Gluteeniton",
 "Normaali",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Normaali",
 "Gluteeniton",
 "Gluteeniton",
 "Normaali",
 "Normaali",
 "Gluteeniton",
 "Normaali",
 "Gluteeniton",
 "Gluteeniton",
 "Normaali",
 "Normaali",
 "Normaali",
 "Gluteeniton",
 "Normaali",
 "Gluteeniton",
 "Normaali",
 "Gluteeniton"]

Above it's returning all meals for day 2, when ir should only return gluten free meals.
Workaround is to chain the find_by queries, which isn't as pretty, but works:

[57] pry(main)> ContentfulMeal.find_by(day:2).find_by(diet_type: "Gluteeniton").load.map{|cm| cm.diet_type}
=> ["Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton",
 "Gluteeniton"]
[58] pry(main)>

Using contentful_model (0.2.0)

@dlitvakb
Copy link
Contributor

Hey @goalaleo,

This looks like a bug,

I'll look into it.

Cheers

@dlitvakb dlitvakb self-assigned this Jan 17, 2017
@dlitvakb dlitvakb added the bug label Jan 17, 2017
@dlitvakb dlitvakb mentioned this issue May 11, 2017
@arielkirkwood
Copy link
Contributor

@dlitvakb Any timeline for this getting a fix?

@dlitvakb
Copy link
Contributor

Hey @arielkirkwood,

contentful_model work has taken a back seat for a while, but I should get back to finishing work on the 2.0 version next month (November), having a 2.0 release ready and released by December.

The fix for this issue should be expected alongside the 2.0 release.

Sorry for the super long wait on this, there's too many things going on on the Contentful world right now, and we're making our best efforts to keep every single library up to date.

Cheers

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

No branches or pull requests

3 participants