Cubezz
Cubezz

Reputation: 13

Symfony query syntax

I have question or problem with query syntax. I have 2 entity tables related with ManyToMany:

Person.php

/**
 * @ORM/ManyToMany(targetEntity="Deal", inversedBy="persons")
 * @ORM/JoinTable(name="persons_deals")
 * /
 protected $deals;

Deal.php

/*
 * @ORM/ManyToMany(targetEntity="Person", mappedBy="deals")
 * /
protected $persons;

This creates an "extra" table called persons_deals in the database. In that table is "person_id" and "deal_id"

If a deal is done there is (for example):

  person_id ---- deal_id

    1 -------------- 1 
    2 -------------- 1

So if I want to get deal_id 1 and persons connected to it. What kind of query should I make?

Upvotes: 1

Views: 80

Answers (2)

Dmitry Malyshenko
Dmitry Malyshenko

Reputation: 3051

There is no such thing as Symfony Query Language (or Syntax). You are probably talking about Doctrine.

So it's better covered at Doctrine documentation how to organize many-to-many relation.

http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html#many-to-many-unidirectional

Pay your attention, you'll probably have to fix namespaces from example to make it work at your code

So instead

  • @ManyToMany(targetEntity="Group")
  • @JoinTable(name="users_groups",

you will need to make

  • @ORM\ManyToMany(targetEntity="Group")
  • @ORM\JoinTable(name="users_groups",

Upvotes: 1

mickburkejnr
mickburkejnr

Reputation: 3690

This is covered in the documentation.

Joining Related Records in Symfony2

Upvotes: 0

Related Questions