1
0
mirror of synced 2024-12-14 23:26:04 +03:00
doctrine2/manual/new/docs/en/improving-performance/other-tips.txt
2007-06-24 20:44:14 +00:00

16 lines
1.1 KiB
Plaintext

**Helping the DQL parser**
There are two possible ways when it comes to using DQL. The first one is writing the plain DQL queries and passing them to Doctrine_Connection::query($dql). The second one is to use a Doctrine_Query object and its fluent interface. The latter should be preferred for all but very simple queries. The reason is that using the Doctrine_Query object and it's methods makes the life of the DQL parser a little bit easier. It reduces the amount of query parsing that needs to be done and is therefore faster.
**Efficient relation handling**
When you want to add a relation between two components you should **NOT** do something like the following:
<code type="php">
// Assuming a many-many between role - user
$user->roles[] = $newRole;
</code> This will load all roles of the user from the database if they're not yet loaded! Just to add one new link! Do this instead:
<code type="php">
// Assuming a many-many between role - user, where UserRoleXref is the cross-reference table
$ref = new UserRoleXref();
$ref->role_id = $role_id;
$ref->user_id = $user_id;
$ref->save();
</code>