findByExample в Доктрине

Есть ли метод в Доктрине как Hibernate findByExample метод?

спасибо

14
задан Pmpr 1 May 2017 в 08:42
поделиться

1 ответ

Да.

Допустим, у вас есть модель, называемая пользователями. У вас есть следующие два класса

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

class User extends Base_User
{

}

в каком-то другом объекте, вы можете сделать

$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"));
10
ответ дан 1 December 2019 в 07:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: