tags:

views:

228

answers:

1

Hi, Is there a method in doctrine like hibernate findByExample method?

thanks

A: 

Yes.

Let's say you have a model called Users. You have the following two classes

abstract class Base_User extends Doctrine_Record 
{
   //define table, columns, etc
}

class User extends Base_User
{

}

in some other object you can do

$user = new User;

//This will return a Doctrine Collection of all users with first name = Travis
$user->getTable()->findByFirstName("Travis");

//The above code is actually an alias for this function call
$user->getTable()->findBy("first_name", "Travis");

//This will return a Doctrine Record for the user with id = 24
$user->getTable()->find(24);

//This will return a Doctrine Collection for all users with name=Raphael and 
//type = developer
$user->getTable()
     ->findByDql("User.name= ? AND User.type = ?", array("Raphael", "developer"));
Travis
Thanks for answer Travis, but it's not what im looking for. I wanna do something like this: $user = new User;$user->name="rafael";$user->category="developer";$q = Doctrine::getTable('User')->findByExample($user);and $q should return a collection of users with "rafael" as name and "developer" as category. Do you know how can do that?
rizidoro
Check the last piece of code that uses the findByDql method. That should get you what you are looking for.
Travis