有没有办法将 SQL 表达式作为 Doctrine2 中的实体字段值传递?
有没有办法做这样的事情:(哑代码)
$entity = new Entity\SomeEntity();
$entity->mappedField = new SQLExpression('SOME SQL CODE HEARE');
$entityManager->persist($entity);
$entityManager->flush();
?
[编辑] 我想从 Oracle tablespace.sequence_name.next
值中的序列插入 ID,我知道这可以通过触发器完成,但我的访问用户无法在我的环境中创建触发器。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果你问一个关于你想要实现的目标的问题,会更有效。
据我所知,这是行不通的,Doctrine2 在将领域模型与持久层混合方面非常独特。这会将您的域层耦合到持久层。
你想达到什么目的?尽管我不确定您要解决什么问题,但事件侦听器可能是您最好的选择。
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.
不需要,Doctrine 可以自己处理 Oracle 序列,请参见 http://www.doctrine-project.org/docs/orm/2.0/en/reference/basic-mapping.html#identifier- Generation-strategies。
另请参阅 Doctrine2 未将序列设置为默认值id 列(postgres)。
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).
您必须记住 Doctrine2 实体映射 SQL 字段。每个数据类型都需要可映射到您的数据库。
字符串变成 varchar 或 blob,整数变成 int 等等。对象没有相应的数据类型,但有一个例外:关系!作为对象关系数据映射器 Doctrine 可以将对象(实体或实体集合)映射到相关表(如果由您定义)。您确实应该更深入地了解 Doctrine 为您提供的功能,如 官方教程。
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.
答案是教义2不可能做到这一点
Answer is that is not possible with doctrine2