Doctrine 2: Find an Entity Using Entity Relationships

I have 3 objects:

Style

Colour

Article

The article has ManyToOne's relationship with both objects (the article is a unique combination of style and color). All objects have an automatic increase in surrogate integer indices.

I have a style element and a Color object, and I want to create a new article that links these two objects if they are not already. Given that there is no way to make an equivalent ("INSERT on DUPLICATE KEY UPDATE") using the doctrine, I need to find any articles that have a BOTH relationship with my Color styles and objects. If there are no matches, create a new object.

How can I find any article object in my system that is associated with style and color objects?

/** * @Entity */ class Style{ /** @Id @GeneratedValue @Column (type="integer") */ private $id; /** @Column (name="name", type="string") */ private $name; /** * @OneToMany(targetEntity="Article", mappedBy="style", cascade={"persist"}) */ private $articles; } class Colour{ /** @Id @GeneratedValue @Column (type="integer") */ private $id; /** @Column (name="name", type="string") */ private $name; } class Article{ /** @Id @GeneratedValue @Column (type="integer") */ private $id; /** * @ManyToOne(targetEntity="Style", inversedBy="articles", cascade={"persist"}) */ private $style; /** * @ManyToOne(targetEntity="Colour", cascade={"persist"}) */ private $colour; } 

The findBy methods described here http://www.doctrine-project.org/docs/orm/2.0/en/reference/working-with-objects.html seem to let you find objects using the string values โ€‹โ€‹of the properties of the entity, and only one of them at a time.

+8
php orm doctrine2 findby
source share

No one has answered this question yet.

See similar questions:

17
Doctrine2 findBy relationship object causes string conversion error

or similar:

1491
What is the "N + 1 selection problem" in ORM (Object Relational Mapping)?
35
Cascade Doctrine Options for OneToMany
nineteen
Undefined doctrine index m: n ratio
one
Associating Propper Objects with a Single Object for the Join Table (Doctrine 2)
one
Doctrine 2, "The Class Does Not Exist," Persistently
one
Symfony2 doctrine mix returns too much data
one
doctrine 2 is many for many with translation
one
Doctrine :: Relation ManyToOne will not work
one
EntityAudit - Doctrine2: using the same object in OneToMany and OneToOne is possible
one
how to add a column to a table using the symfony2 doctrine

All Articles