canni
canni

Reputation: 5885

Is there a way to pass a SQL expression as a entity field value in Doctrine2?

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

Answers (4)

canni
canni

Reputation: 5885

Answer is that is not possible with doctrine2

Upvotes: 0

FloydThreepwood
FloydThreepwood

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

Marijn Huizendveld
Marijn Huizendveld

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

Related Questions