Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
proper way to generate a WHERE IN query
  • I'm accepting a comma seperated list of IDs within a form post and want to find all models of a certain type within that last of IDs. I fell back on looping through them and loading one at a time because I was having too much trouble getting it to work. Is there a one-liner using either {{Model}}::find or the ORM methods that will allow me to do this?
  • You can do
    Model_Name::find()->where('field', 'IN', array(1,3))->get();
    
  • Awesome thanks Harro! I was just missing the ->get();
  • What about where not in? is it just
    Model_Name::find()->where('field', 'NOT IN', array(1,3))->get();
    ?
  • Activate the profiler, and check what SQL is generated. I assume it won't be an issue.
  • Ok will do

  • I used it

    Model_Name::find()->where('field', 'IN', array(1,3))->get();
    but I got this error:

    Fuel\Core\FuelException [ Error ]: Invalid method call. Method where does not exist.


  • I solved it, I should be using query() instead of find()

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion