Filters in Doctrine

807 Views Asked by At

nHibernate has a great feature called filters, so i can create criterias globally for my applications. I'm starting a project in PHP and i need to use an ORM, i'd like to know if Doctrine has a similar feature to manage query conditions.

thanks

2

There are 2 best solutions below

2
Travis On

I think what you are looking for are Doctrine Query Hooks.

There a numerous hooks for preUpdate, preSave, preCreate, postCreate, postUpdate, postSave, preSelect, and so on and so forth.

Hope this helps.

0
Jasper N. Brouwer On

Doctrine 2.2 features a filter system that allows the developer to add SQL to the conditional clauses of queries, regardless the place where the SQL is generated (e.g. from a DQL query, or by loading associated entities).

The filter functionality works on SQL level. Whether a SQL query is generated in a Persister, during lazy loading, in extra lazy collections or from DQL. Each time the system iterates over all the enabled filters, adding a new SQL part as a filter returns.

By adding SQL to the conditional clauses of queries, the filter system filters out rows belonging to the entities at the level of the SQL result set. This means that the filtered entities are never hydrated (which can be expensive).