All Questions
Tagged with many-to-one doctrine-orm
68 questions
1
vote
1
answer
705
views
Symfony: Persisting in a "ManyToMany with extra data" after implementing bridge entity
I am trying to persist a "collection" of objects that are related between them through an entity that is in a ManyToOne relation with two other entities in order to provide a kind of "...
0
votes
1
answer
322
views
When deleting an entity with associate all related data is deleted but want to keep associate data in symfony
I have two entities which are below :-
Website
Posts
In the website entity, I have given OneToMany relation, And in the posts entity, I have given the ManytoOne relation.
Website Entity:-
/**
* @...
0
votes
2
answers
2k
views
Doctrine ORM self ManyToOne fails to insert because of duplicate entries
Problem
Is there a way that Doctrine recognizes the existing objects when persist with cascade={"persist"} on a ManyToOne relation instead and do not fail when trying to insert it again and ...
1
vote
1
answer
586
views
Doctrine & ManyToOne Foreign key issue
I'm trying to create a relation between a Language entity and a User entity, one language has many users, but a user has one language.
So I created this relation as follow :
In User.php:
/**
* @ORM\...
3
votes
1
answer
5k
views
Symfony 4/Doctrine 2 - fetching real object not the proxy
I have a following entity:
/**
* @ORM\Entity(repositoryClass="App\Repository\CourseLevelRepository")
*/
class CourseLevel
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(...
0
votes
1
answer
493
views
How to reference many-to-one association in Doctrine 2 by a non-primary key
As I understand, Doctrine requires many-to-one associations to reference the primary key on the one side. (See here or here)
How would one solve a many-to-one association referenced by an unique key ...
0
votes
1
answer
303
views
Doctrine persisting Many-To-One entities
I'm using Zend Framework 3 with Doctrine and I'm trying to save an Entity "Cidade" related to another Entity "Estado" witch is already stored in the database. However, Doctrine is trying to persist ...
1
vote
0
answers
89
views
Remove all related children in Symfony entity ManyToOne
That is my relations:
in CategoryField Entity:
manyToOne:
category:
targetEntity: Category
inversedBy: fields
joinColumn:
name: category_id
...
0
votes
1
answer
57
views
Doctrine, ralation ManyToOne
When a try update my database I got error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
(symfony.#sql-d8c_55, CONSTRAINT ...
0
votes
2
answers
73
views
doctrine2, retrieve associated data from inverse side
I have 2 entities. The simple logic is that a user has many delivery address, so in the future they will be able to choose one of them for their deliveries.
First entity, Direccion (address).
<?php ...
0
votes
0
answers
80
views
doctrine ManyToOne relation crashes symfony 3.3.1
We have an old postgres 9.2 database with more than 400 tables. I used the symfony console to generate the entities, I created the repository classes that I need myself.
When I remove all relations ...
0
votes
1
answer
2k
views
How to remove a collection element without EntityManager#remove(...) in Doctrine 2?
I have a classical construction like EntityA OneToMany EntityB. Implemented as a bidirectional relationship:
the EntityB has a property $entityA of type EntityA and
the EntityA has a property $...
0
votes
1
answer
2k
views
How to persist only one end of a relationship and the other one only if the entity doesn't exist?
I have a complex/nested object created by automatic hydration from Zend\Form data. Now I want to save it with Doctrine 2. The best case would be just one persist(...) and one flush(...) call on the ...
0
votes
0
answers
112
views
How to deactivate the cascading saving in Doctrine 2?
I have Entities Foo and Bar with a bidirectional ManyToOne relationship:
/**
* Foo
*
* @ORM\Table(
* name="foo",
* indexes={
* ...
* }
* )
* @ORM\Entity
* @ORM\...
4
votes
2
answers
8k
views
Symfony Doctrine Hydrator - With custom hydrator I lose my ManyToOne relation
I would like to extends ObjectHydrator to benefit of the hydration of my ManyToOne relation and add extra field to the Entity.
Here is my hydrator: StatisticsDataHydrator.php
namespace AppBundle\...
0
votes
2
answers
323
views
In Doctrine2, cannot remove unidirectional many-to-one relation (cannot set to null)
I have an Authentication entity that works like a user entity, and a Country entity which has a property related to Authentication entity unidirectionally:
/**
* @var Authentication
*
* @ORM\...
0
votes
1
answer
32
views
How to remove owing side from inversed MTO relation side without cascade option?, how to update the inversed side of relation?
How to remove owing side from inversed MTO relation side without cascade option? , how to update the inversed side of relation without cascade option?
Error is that if i change address(OTM) of the ...
0
votes
1
answer
2k
views
ManyToOne on queryBuilder symfony 3
I have 2 entities Federation and Pays , the entity Federation has a property ManyToOne:
/**
* @ORM\ManyToOne(targetEntity="Stage\AdminBundle\Entity\Pays")
*/
public $nomPays;
I ...
1
vote
1
answer
1k
views
Symfony schema:update error
I have an error which i can't fix cause i can't find the problem.
The error in the console says:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected 'public' ...
0
votes
2
answers
885
views
Doctrine select many from the one (many-to-one unidirectional (different bundles))
Working on a legacy project which restricts the options available, has left me in a situation where I need to solve the following problem, ideally with doctrine.
I have two entities in different ...
1
vote
1
answer
71
views
Symfony 3 and Doctrine relationship
I am having two entities A and B. Let's say entity A has a primary key 'foo' and the entity B has a variable named 'bar'. I am trying to establish the "Many to one" association between these two. And ...
0
votes
1
answer
719
views
Symfony create new object many to one error call undefined method
I have set up a many to one relation and want to add a new product-object linked to its category. Related to this I have 2 questions:
I get stuck on saving the category object to the new product. ...
1
vote
1
answer
121
views
How to reference child elements in a Many-to-One relationship in ZF2 and Doctrine
If I develop a project using ZF2 and Doctrine that hydrates an object with a Many-to-Many relationship similar this Doctrine hydrator tutorial, the parent fieldset would look like this:
namespace ...
1
vote
2
answers
1k
views
Doctrine clear() and many to one relation
I need to import large data from csv file (about 1m records).
For avoid memory leaks I tried bulk insert from doctrine documentation:
$batchSize = 20;
for ($i = 1; $i <= 10000; ++$i) {
//code
...
2
votes
1
answer
4k
views
Doctrine targetEntity abstract class
I get unnecessary queries then entity has ManyToOne relationship with abstract class.
My classes structure:
/**
* @ORM\Entity
* @ORM\Table(name="tb_payment_info")
* @ORM\InheritanceType("JOINED")
...
1
vote
1
answer
372
views
Symfony form many-to-many -> many-to-one
I have three different entities
- Newsletter
- NewsletterOptions
- Options
I need the NewsletterOptions entity, because I need extra properties in that entity, so a manyToMany relation is no option. ...
0
votes
2
answers
85
views
Doctrine2 Save Many To One Objects
The relation is: MailTemplate may be used by many EMail but EMail is associated only to one MailTemplate.
The problem occurs when trying to insert new records. The error is:
Cannot access empty ...
0
votes
1
answer
573
views
Doctrine 2 @ManyToOne attribute always return null
I have these entities
/** @ORM\Entity */
class Produto {
/* Other attributes */
/**
* @ORM\ManyToOne(targetEntity="Produto\Entity\Categoria")
* @ORM\JoinColumn(name="categoria_id"...
1
vote
0
answers
417
views
Doctrine many to one relationship versioning
I have an application that I'm developing in symfony 2 with doctrine. The problem I'm facing is the slowly changing dimension.
For example I have three Entities: Dossier, Payout and PayoutCategory. ...
0
votes
0
answers
418
views
Many to One Unidirectional relation in symfony2 has "No Association error"
I am trying to create a many to one unidirectional relationship between two tables. dateTime and availibilityList are two entities, one list may have multiple date and time.
I added the annotations ...
0
votes
1
answer
681
views
Doctrine Orm - multiple OneToMany joins to the same table
I am struggling with the following. I am writing a basic User / Order relationship where a number of users play different roles. Each order is therefore linked to a user who is the initiator of the ...
0
votes
1
answer
2k
views
Many to One Relation in Symfony 2
I have a problem related to Doctrine2:
1- I have two tables joining on a many-to-one relation:
Table 1 - Activity
The Schema:
Backend\adminBundle\Entity\Activity:
type: entity
table: activity
...
0
votes
1
answer
660
views
How to set up a zf2 form for a ManyToOne doctrine mapping
I'm having trouble hydrating a form in zf2 using a doctrine ManyToOne unidirectional relationship. My entities look like this:
namespace AdminMyPages\Entity;
class MyPageItem
{
// ...
/**
...
0
votes
1
answer
628
views
How to configure entities in zf2 for ManyToOne unidirectional doctrine mapping
I'm having trouble developing a form in zf2 using a doctrine ManyToOne unidirectional relationship. My entities look like this:
namespace AdminMyPages\Entity;
class MyPageItem
{
// ...
/**...
0
votes
1
answer
647
views
Symfony2 Many to one - one to many without join table
I have "Project" entity which can have several Benefits, while a benefit belongs to just one Project:
To me it seems a many to one - one to many relationship.
I followed the indication here
The ...
0
votes
1
answer
108
views
Children count depends on method in test
While experimenting with a self-referencing ManyToOne entity I find the count of children depends on the method used to find the parent. If the Repository is used, the test fails with Failed ...
0
votes
1
answer
818
views
can we use traits to map manyToOne relationship with doctrine2?
I am frequently associating a vote entity in other ones with symfony2 / doctrine 2. This is done through a manyToOne relationship.
I was considering using a trait to include the association and its ...
0
votes
2
answers
2k
views
Doctrine2: Many-to-One delete relations on update
I have a software which can own many screenshots.
This is the software class:
class Software
{
public function __construct()
{
$this->screenshots = new ArrayCollection();
}
/**...
0
votes
1
answer
3k
views
Symfony/Doctrine 2 ManyToOne relationship, ORM does not retain set value for column, error ensues
I'm creating a ManyToOne relationship in table B, to one entry in table A.
I am using a particular key_id parameter, which is set in the controller, before being flushed to the db. My problem is ...
9
votes
2
answers
2k
views
Symfony2 / Doctrine2 - ManyToOne - Save inverse side
I am new to Symfony and Doctrine.
I have an entity "User" and an entity "Type". One user can have one favorite type and one type can have many users that have that specific type as favorite. So I ...
0
votes
1
answer
239
views
Symfony2 / Doctrine : OneToMany/ManyToOne between 2 bundles
I have 2 bundles : a core one (C) and an optional one (O).
I create an entity in O with a OneToMany property referring an entity in C.
I want to inject the related ManyToOne in the entity in C (I ...
7
votes
1
answer
3k
views
Two attributes sharing the same OneToMany relationship to one entity Symfony2
Let's first describe my situation. I am using Symfony2 and I have a problem with a relationship between my entities.
I have two entities that are linked together. The two entities are ...
4
votes
1
answer
197
views
Adding Entity with Many-To-One association and inverse side already existing in the database
Using Doctrine 2 with Zend Framework 2. Been thinking of how I am meant to persist an entity with a field having a Many-To-One association with another entity that already exists in the database. ...
0
votes
1
answer
197
views
Doctrine2 Associations mapping and doctrine annotations
I've broken my head trying to set annotations for my 2 entities in order to use join tables.
I have 2 tables: user and cart.
Cart contains user ids with products which users selected.
1 user can have ...
3
votes
0
answers
1k
views
Doctrine OneToMany cascade persist on foreign key
i've trouble with a OneToMany relation. I'm currently working on a log analyser, that stores the original log rows as well as the parsed message from the row including the keywords. The Database ...
2
votes
1
answer
503
views
build form for tables with many relations
I have got a problem to build a forms with many relations between tables. The structure of relations you can see on below picture:
My relations in YML:
######### Products.orm.yml #########
type: ...
3
votes
1
answer
2k
views
How to handle a file upload with a many to one relationship in Symfony2?
I'm creating a ticket system for practice purposes.
Right now I'm having a problem with uploading files.
The idea is that a ticket can have multiple attachments, so I created a many-to-one ...
11
votes
1
answer
14k
views
Doctrine OneToMany relationship error
I am trying to set up some ManyToOne/OneToMany relationships on objects in my database using Doctrine (2.2.3+) via Symfony2 (2.3.0) and am getting a strange error. Here are the relevant parts of the ...
2
votes
1
answer
4k
views
Doctrine2: Many-To-Many with extra columns in reference table (add record)
Spoiler: I think I found the answer but I'm not 100% sure ;)
I've been looking at this question for a while but I cannot manage to make it work. So I've create dummies Entities to test the relation ...
0
votes
1
answer
4k
views
Symfony 2 - ManyToOne Bidirectional relationship behaviour
I had a big time trying to figure out how to setup a ManyToOne -> OneToMany relationship with Doctrine 2 and it still not working...
Here is the application behaviour:
A site has Pages
A User can ...