Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM where_or statement for relations
  • Perhaps kind of a strange title. However, this is my code: 

    Model_Post::find('all', array(
    'where' => array(
    array('group_id', $id),
    ),
    'related' => array(
    'mentions' => array(
    'where' => array(
    array('mention_type' => Config::get('types.group')),
    ),
    ),
    ),
    'order_by' => array(
    'updated_at' => 'DESC'
    ),
    ));

    This does not deliver the correct results because I would like the global 'where' and the related 'where' to by an OR statement. So I want posts with an specific group_id OR with a specific mentions.mention_type. 

    How can I do this? I have never found any documentation on OR statements
  • HarroHarro
    Accepted Answer
    You can use 'or_where', but I'm not sure that works in array notation too, you'll have to try.
  • Thank you! This eventually did it: 

    Model_Post::find('all', array(
    'or_where' => array(
    array('group_id', $id),
    array('mentions.mention_type', Config::get('types.group')),
    ),
    'related' => array(
    'mentions',
    ),
    'order_by' => array(
    'updated_at' => 'DESC'
    ),
    ));

Howdy, Stranger!

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

In this Discussion