2

I am developing an application using idiorm(https://github.com/j4mie/idiorm) for fetching data from database.

Here is my piece of code:

$messages = Model::factory('Messages')->where('from_user_id','1')->find_many();

I want to include an or statement that where->('to_user_id','1')

How can I put this as an OR statement in my Idiorm query?

Dasmond Miles
  • 183
  • 2
  • 10
  • Dare I suggest you `RT"Fragrant"M` [which is here](http://idiorm.readthedocs.io/en/latest/) I know its a place of last resort, but give it a go. It took me 3 minutes to find it in there, how long did it take for you to write this question? – RiggsFolly May 18 '16 at 19:20

2 Answers2

5

This looks like what the manual is telling you to do for an OR condition

$messages = Model::factory('Messages')
                   ->where_any_is(
                                  array(
                                         array('from_user_id' => 1),
                                         array('to_user_id' => 1)
                                       )
                                  )    
                   ->find_many();
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
2

I'm not familiar with idiorm, but looking at the source code you should be able to use where_raw to build your own where clause:

    /**
     * Add a raw WHERE clause to the query. The clause should
     * contain question mark placeholders, which will be bound
     * to the parameters supplied in the second argument.
     */
    public function where_raw($clause, $parameters=array()) {
        return $this->_add_where($clause, $parameters);
    }

Something like ->where_raw('from_user_id = ? OR to_user_id = ?', array(1, 1))

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115