doctrine-orm

How to delete rows from join-table (ManyToMany) in Doctrine?

走远了吗. 提交于 2021-02-04 14:23:26
问题 I have a join-table which is created by using @ORM\ManyToMany annotation in Symfony2/Doctrine. It joins Category and Parameter table. Now I want to delete all parameters from the Parameter table. Because there are foreign key constraints defined on join-table I can't just delete rows from Parameter table. First I have to delete child rows from join-table. But Dotrine's DQL syntax require to give a name of the entity, like: DELETE Project\Entity\EntityName But what is the name of the join

symfony/serializer usage with object collection

…衆ロ難τιáo~ 提交于 2021-01-29 20:29:40
问题 Symfony serializer lost collection object while denormalizing. Example: We have some entity with collection in the property (I'm using Doctrine ArrayCollection but it is reproduced for any Collection which implement PHP Iterator interface) Let's serialize and deserialize it with Symfony and JMS serializer and compare results: Origin: ^ App\Entity\Entity^ {#195 -rewardItems: Doctrine\Common\Collections\ArrayCollection^ {#179 -elements: array:2 [ 0 => App\Entity\Item^ {#224 -type: 1 } 1 => App

The class was not found in the chain configured namespaces

ε祈祈猫儿з 提交于 2021-01-29 12:51:44
问题 Hello, i need to explain what i'm was doing at first: I was on a project and for some reason I ended up having to use two databases instead of just one. so i do what it was needed to do, i change my doctrine.yaml settings with what is explain in the symfony doc and in that moment the error appeared An SQL error that says that it was no column found for X request on X table (the error is SQLSTATE[42S02], but it's not important) (in parallel of that error i need to say that the "--em" shit didn

Force 'fetch joined' relations to include IDENTITY of their ManyToOne relations using HYDRATE_ARRAY?

风流意气都作罢 提交于 2021-01-29 10:58:19
问题 I have a query in which I'm joining a number of tables to my original Person entity. A Person may have multiple Child relations (OneToMany), and a Child may have a School they go to (ManyToOne). Problem is, I don't need the entire School entity that connects to each child, only their id , which is already stored on Child . I'm using a Paginator to iterate through the results and I use HYDRATE_ARRAY to reduce overhead of the ORM parsing data to entity objects. But the id fields of unfetched

Doctrine return error with “eq”, no with “in”

给你一囗甜甜゛ 提交于 2021-01-29 08:33:46
问题 With Symfony and Doctrine, I have an error with "eq" subquery : It's OK, no error : public function getForums() { $qb = $this->createQueryBuilder('fc'); return $qb ->innerJoin('fc.versions', 'fcv') ->innerJoin('fc.versions', 'fcvl', 'WITH', $qb->expr()->in( 'fcvl.id', $this->_em->createQueryBuilder() ->select('MAX(v.id)') ->from(ForumCategoryVersion::class, 'v') ->where('v.forumCategory = fc') ->getDQL() )) ->select('fc, fcv') ->getQuery() ->getResult(); } Replace in by eq : public function

How to efficiently load last item in ArrayCollection?

泪湿孤枕 提交于 2021-01-29 08:00:18
问题 I have the following 2 entities: public class Domain { ... /** * @ORM\OneToMany(targetEntity="Application\Entity\Ping", mappedBy="domain", cascade={"persist", "remove"}, fetch="EXTRA_LAZY") * @ORM\OrderBy({"time" = "ASC"}) */ private $pings; ... } and: class Ping{ ... /** * @ORM\ManyToOne(targetEntity="Application\Entity\Domain", inversedBy="pings") * @ORM\JoinColumn(name="proj_id", referencedColumnName="proj_id") */ private $domain; ... } I have currently a couple of hundred domains with 5K

DQL LEFT JOIN - sql example

一笑奈何 提交于 2021-01-28 16:43:28
问题 well-functioning SQL is: SELECT ro.id_role ,rr.id_role_resource ,re.id_resource FROM resource re LEFT JOIN role_resource rr ON rr.resource_id = re.id_resource LEFT JOIN role ro ON ro.id_role = rr.role_id now I must write DQL- this is table shema: role: id_role, name role_resource: id_role_resource, role_id, resource_id, permission resource: id_resource, controller,action ... in the last table are no corresponding records in the table role_resource. That's why i need this left Join Query in

Doctrine Is not a valid entity or mapped super class

寵の児 提交于 2021-01-28 16:32:14
问题 i have a problem with doctrine and i getting this error from auto generated entity file "Class "Users" is not a valid entity or mapped super class.". File and comments inside looks like fine i dont understund why or i something miss? Some piece of code <?php use Doctrine\ORM\Mapping as ORM; /** * Users * * @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"username"})}) * @ORM\Entity */ class Users { /** * @var integer * * @ORM\Column(name="userid",

Doctrine Is not a valid entity or mapped super class

喜你入骨 提交于 2021-01-28 16:29:28
问题 i have a problem with doctrine and i getting this error from auto generated entity file "Class "Users" is not a valid entity or mapped super class.". File and comments inside looks like fine i dont understund why or i something miss? Some piece of code <?php use Doctrine\ORM\Mapping as ORM; /** * Users * * @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"username"})}) * @ORM\Entity */ class Users { /** * @var integer * * @ORM\Column(name="userid",

WHERE … IN query with sub-query in Doctrine queryBuilder or equivalent

穿精又带淫゛_ 提交于 2021-01-28 07:01:34
问题 In my Symfony 4 project I have a User entity and a UserRepository . I'm trying to implement the equivalent of this SQL query in the QueryBuilder (Doctrine 2) or even in DQL . SELECT * FROM user WHERE account_manager_id IN (SELECT id FROM user WHERE account_manager_id = :managerAdminId AND roles LIKE '%ROLE_MANAGER%') Or maybe use a different syntax. I tried different things, but couldn't figure out how to write the WHERE ... IN with the sub-query. This is all I could come up with, which I don