Question

How to add a not equal condition in phpactiverecords?

Code_reference::find('all', array('code' => $name), array('conditions' => 'id != '.$code_id))
Était-ce utile?

La solution

Try use <>

Code_reference::find('all', array('code' => $name), array('conditions' => 'id <> '.$code_id))

Autres conseils

In your example, the second $options array will get ignored. You have to merge them yourself and thus cannot use the compact hash-mode anymore.

CodeReference::all(array('code = ? AND id != ?', $name, $code_id));

To print the SQL query, you can use last_sql.

CodeReference::table()->last_sql

For more details, please refer to the official (but yet laggy) documentation:

http://www.phpactiverecord.org/projects/main/wiki/Finders#conditions

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top