Reputation: 5885
Is there a way to do something like this: (dumb code)
$entity = new Entity\SomeEntity();
$entity->mappedField = new SQLExpression('SOME SQL CODE HEARE');
$entityManager->persist($entity);
$entityManager->flush();
?
[EDIT]
I want to insert ID from sequence in Oracle tablespace.sequence_name.next
value, I know that this can be done from trigger, but my access user is not able to create triggers in my env.
Upvotes: 0
Views: 285
Reputation: 1585
You have to remember that Doctrine2 Entitys map SQL Fields. Every datatype needs to be mappable to your database.
A String becomes a varchar or blob, a integer becomes a int etc. Objects have no corresponding datatype with one exception: Relations! As a Object Relational Data-mapper Doctrine can map a Object (Entity or EntityCollection) to a related table, if defined by you. You really should take a deeper look in the capabilities Doctrine gives you to define these as stated in the official tutorial.
Upvotes: 0
Reputation: 49583
No need to, Doctrine can handle Oracle Sequences by itself, see http://www.doctrine-project.org/docs/orm/2.0/en/reference/basic-mapping.html#identifier-generation-strategies.
And see also Doctrine2 doesen't set sequence to default for id column (postgres).
Upvotes: 0
Reputation: 791
It would be a lot more effective if you ask a question about the thing you are trying to achieve.
As far as I know this won't work, Doctrine2 is very peculiar about mixing the domain model with the persistence layer. This would couple your domain layer to your persistence layer.
What is it you're trying to achieve? You're probably best served with an event listener, though I'm not sure what problem you're trying to solve.
Upvotes: 1