Hi all,
I was wondering if there is something planned like "find by example" or "delete by example".
E.g.
$user = User::model();
$user->name = 'nomar'
$user->delete();
results in
DELETE FROM user WHERE name = 'nomar';
or
$user = User::model();
$user->name = 'nomar'
$user->findAll();
results in
SELECT * FROM user WHERE name = 'nomar';
So, basically the models properties are populated with more sensible values then in the example and then you could just delete or search.
The search feature is somehow implemented afaik - but returns a CActiveDataProvider instead of an array with all results.
IMHO this would make searching and deleting much more elegant - I have a hard time writing findByAttributes(…);
The code gets really unreadable if you are searching for more then one attribute.
On top of this mighty AR-Framework it should be really easy to implement.
What do you think?
UPDATE
I wrote my suggested methods for one of my models an it does not feel right.
Creating an Object for this operation is strange, and handling the results is also not so nice, espacially when searching - deleting is ok with me.
Maybe something like
$users = User::findByExample(array('name' => 'nomar'));
User::deleteByExample(array('name' => 'nomar'));
would be better.
And the possibility to pass in an real model instead of an array