I am moving from Doctrine 1 to Doctrine 2.
And am using this function synchronizeWithArray() in Doctrine 1 and need to use it in Doctrine 2 .. Is this function exist in Doctrine 2 or any equivalent function ?
Thanks
Related
In my ZF3 application I want to map an entity "User" having a property "plan" to another entity with could be one of the following classes "PlanA", "PlanB" or "PlanC" using Doctrine 2 ORM. A "User" can have one "Plan", a "Plan" can be associated with many "Users".
I looked into discriminator maps, but I am not sure that that's the right approach.
Any ideas/code sample for that?
I'm using Doctrine in combination with an Oracle database. I use platform-specific features heavily, so I already created a bunch of custom DQL functions. But now I ran into a serious problem. To do a LIKE query with a regular expression, Oracle offers the REGEXP_LIKE operator. It looks like a function, but really acts as a relational operator. Unfortunately, Doctrine only allows me to create custom functions, not operators. I cannot use it like a function, because Doctrine requires me to make it a complete expression, e.g. REGEXP_LIKE(foo, bar) != 0. But for Oracle that's a syntax error.
As a workaround, I use this contraption in the getSql method of my custom DQL function:
CASE REGEXP_LIKE(foo, bar) THEN 1 ELSE 0 END
Looks ugly, though. Is there a better way to get this working in Doctrine??
regexp_like in Oracle is only allowed in the criteria part of the SQL statement; but what you can use is the true Oracle function regexp_count in a case clause:
select col1, col2, -- etc
case (regexp_count(col3, '^Hey$'))
when 0 then 0
else 1
end as found
from table;
So for your example REGEXP_LIKE(foo, bar) != 0 would become REGEXP_COUNT(foo, bar) != 0
I noticed that in tutorials there are different ways of instantiating the querybuilder.
1. $em->getRepository("Users")->createQueryBuilder('u')
2. $em->createQueryBuilder();
Is there a significant difference in using it with or without repository?
QueryBuilder in the repository will preset the from and select parts for you whereas the second one creates an empty QueryBuilder.
I am so new to Doctrine 2 and not that good with regards to database table relationships. I understand the way of how Many to One, One to Many, One to One and Many to Many relationship works. I am just confused with this error I got below from generating database tables using the doctrine CLI.
[Doctrine\ORM\ORMException]
Column name `id` referenced for relation from Kent\Entity\DoctorSpecialties towards Kent\Entity\Doctors does not exist.
Please see this github link to view my entities. (Doctors.php & DoctorSpecialties.php)
https://github.com/aldee07/Doctor-Finder/tree/development-september/library/Kent/Entity
Note: I am using Zend Framework 1.11.12
That are the annotations you must put on DoctorSpecialties class
#ManyToOne(targetEntity="Doctors")
#JoinColumn(name="doctor_id", referencedColumnName="doctor_id")
in Many to many relationship you have to give the reference to the third forignkey table
so change this
/**
*
* #var Doctors
* #ManyToMany(targetEntity="Doctors", mappedBy="specialties")
* #JoinTable(name="doctor_specialties")
*/
protected $doctors
hope this helps
I think is better you look here:
http://www.doctrine-project.org/jira/browse/DDC-2646?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel
How can I add a CHECK .. IN constraint, like in the code below, in Doctrine 2?
CREATE TABLE table_name (
colum_name VARCHAR(1)
CHECK (column_name IN ('A','B','C'))
);
-- edit: I use annotations to define my entities
This is not supported by the ORM itself. You can define custom DDL to be used for those columns through your metadata driver. For instance, in the AnnotationDriver you can use /** #Column(type="string", columnDefinition="VARCHAR(1) CHECK (column_name IN ('A','B','C'))") */ as defined in the Annotations Reference.
I would avoid it anyway and keep those checks on application level.