Questions tagged [doctrine-collection]
13 questions
7
votes
2 answers
Get last element in Collection
I'm trying to get a property on the last element in a collection. I tried
end($collection)->getProperty()
and
$collection->last()->getProperty()
none works
(tells me I'm trying to use getProperty() on a boolean).
/**
* Get legs
*
* @return…

Pierre Olivier Tran
- 1,669
- 4
- 24
- 40
7
votes
2 answers
DoctrineCollection: difference between toArray() and getData()
Basically, if I had a DoctrineCollection of DoctrineRecord objects, and wanted to convert it to an array, I could use:
$collection->toArray() or $collection->getData()
But I don't understand what's the difference between this two methods.

NadiaFaya
- 224
- 4
- 9
3
votes
5 answers
How to return an empty Doctrine_Collection?
I've a method that returns a Doctrine_Collection, with a whereIn() clause :
public function getByValues($values)
{
if (!is_array($values))
throw new sfException('Wrong parameter type. Excepted array.');
return Doctrine_Query::create()
…

Clement Herreman
- 10,274
- 4
- 35
- 57
0
votes
2 answers
How to associate objects of one-to-many relationships?
I'm using symfony 1.4 with Doctrine ORM.
I have two classes related by a one-to-many relationship, and I have the object of the "one side". I need to associate this object , let's say A, to the "many side" object, let's say B. The thing is A have…

Throoze
- 3,988
- 8
- 45
- 67
0
votes
1 answer
How to cleanly update Doctrine Collections in Symfony while both creating and removing elements?
I'm having an issue with Doctrine Collections (using Symfony 6.2.9 and doctrine/orm 2.14.2) .
The objective :
I am parsing a config file from a firewall, and creating elements into my database (the firewall entity + policies + interfaces). On the…

Thomas Cochard
- 41
- 5
0
votes
1 answer
Sort doctrine collection by field from array list
I have a doctrine collection with several objects. Each object has a field called control. The field holds a number.
How do I return a set of objects from the collection, matching and arranged in control order of a given array (in this case, [1616,…

John Miller
- 527
- 4
- 15
0
votes
1 answer
Reuse a Doctrine_Record object to save multiple instances of a model
I am working on some kind of notifications module in a Symfony application. I am iterating over a Doctrine_Collection of users to create a Notification for every user that has a flag active in its profile:
// Create and define common values of…

elitalon
- 9,191
- 10
- 50
- 86
0
votes
1 answer
Diff of two Doctrine_Collection instances
I have a collection of users who completed a certain test and a list of users who got an invite for that test. Now I'd like to fetch all the users who did not complete the test. I thought it'd be simple to diff the two collections (like arrays), but…

Jurian Sluiman
- 13,498
- 3
- 67
- 99
0
votes
0 answers
Filtering collections using row constructors
How does one filter a Doctrine collection using a row constructor similar to what can be done with SQL such as SELECT whatever FROM t WHERE (col1, col2) IN ((val1a, val2a), (val1b, val2b), ...);?

user1032531
- 24,767
- 68
- 217
- 387
0
votes
1 answer
Doctrine ArrayCollection matching criteria function results in Undefined property: MyEntity::$1 (Symfony 3.4)
I defined an Entity "TrainingProgressEntry" as an @ORM\Entity and a "training" property like this:
/**
* @ORM\ManyToOne(targetEntity="Training", inversedBy="training_progress")
* @ORM\JoinColumn(name="training_id", referencedColumnName="id")
…

user3440145
- 793
- 10
- 34
0
votes
1 answer
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 $entityBs, that contains an ArrayCollection of EntityB…

automatix
- 14,018
- 26
- 105
- 230
0
votes
1 answer
Cannot save a Doctrine_Collection
I am using Docrine 1.2 with Zend Framework and trying to save a Doctrine Collection.
I am retrieving my collection from my table class with the following code.
public function getAll()
{
return $this->createQuery('e')
->orderBy('e.order ASC,…

Garry
- 1,455
- 1
- 15
- 34
-1
votes
1 answer
Doctrine_Collection __toString() type of functionality
Anyone have any ideas on the best way to convert a Doctrine_Collection to a CSV based on a specific column name?
Example array:
array
0 =>
array
'id' => string '2' (length=1)
'name' => string 'metallica' (length=14)
…

Mike Purcell
- 19,847
- 10
- 52
- 89