1

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?

1
  • You should look into Doctrine (which this is using). You don't really work with SQL or tables, you work with objects and classes. $person->setDeal($deal) Commented Jul 10, 2015 at 8:19

2 Answers 2

1

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",
Sign up to request clarification or add additional context in comments.

Comments

0

This is covered in the documentation.

Joining Related Records in Symfony2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.