Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
OR in where clause
  • Hi, I want to use the array syntax for passing the WHERE clause in Orm::find but I can't figure out how to get ORs in there. Can any one tell me how I have to build the array to get something like:
    (A = 1 OR A = 3) AND active = true
    

    Thanks!
  • Works just like the DB query builder:
    Model_Example::query()->where_open()
            ->where('A', '=', 1)
            ->or_where('B', '=', 2)
        ->where_close()
        ->where('C', '=', 3)
        ->get();
    
  • Thanks for your reply. I need to be able to build the query up. Looking at the code it looked to me like something like this should work but I didn't have any luck.
    $where = array(
       'or' => array(
              array('A',1),
              array('A',3),
       );
    

    What is the correct way to go about building the where cause at run time? Thanks
  • The model methods return themselfs so you can chain. Nobody's saying you should do that all in one go
    // this is the same as
    Model_Example::query()
        ->where_open()
            ->where('A', '=', 1)
            ->or_where('B', '=', 2)
         ->where_close()
         ->where('C', '=', 3)
         ->get();
    
    // this...
    $q = Model_Example::query();
    
    $q->where_open()
            ->where('A', '=', 1)
            ->or_where('B', '=', 2)
         ->where_close();
    
    $q->where('C', '=', 3);
    
    $q->get();
    
  • I see. Thank you very much!

Howdy, Stranger!

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

In this Discussion