It doesn't look like this question is related to Doctrine 2 (or Symfony 2), but 
rather to whatever implementation you use to representing the result as the 
arrays you're showing us.

So my counter-questions would be:
- Where do these arrays come from?
- How do you produce them?
- Are you using a 3rd party library to do this?

-- 
Jasper N. Brouwer
(@jaspernbrouwer)


On 14 November 2014 at 12:23:36, Andrius Kulbis ([email protected]) 
wrote:
> I have the following setup of related db tables:
> 
> Organization
> +--------+---------+
> | id | integer |
> +--------+---------+
> | name | string |
> +--------+---------+
> 
> 
> Division
> +---------------+---------+
> | id | integer |
> +--------+----------------+
> |organization_id| integer |
> +---------------+---------+
> | name | string |
> +---------------+---------+
> 
> 
> Subdivision
> +---------------+---------+
> | id | integer |
> +--------+----------------+
> | division_id | integer |
> +---------------+---------+
> | name | string |
> +---------------+---------+
> 
> 
> I'm using the Symfony2 with Doctrine2 ORM and FOSRestBundle
> 
> Now I got confused with the Association Mapping.
> 
> When I require for a Organization, I would like to get the following
> 
> 
> {
> id: 1,
> name: "organization1",
> divisions: [
> {
> id: 1,
> organization_id: 1,
> name: "division1"
> subdivisions: [
> {
> id: 1,
> division_id: 1,
> name: "subdivision1"
> }
> ]
> }
> ]
> }
> 
> 
> I figured out this one, and used One-To-Many bidirectional association
> mapping of Doctrine.
> 
> What gave me a headache, is the opposite direction of the relation.
> If I require for a specifig Subdivision, I would like to get the
> following:
> 
> {
> id: 1,
> division_id: 1,
> name: "subdivision1",
> division: {
> id: 1,
> organization_id: 1,
> name: "division1"
> organization: {
> id: 1,
> name: "organization"
> }
> }
> ]
> }
> 
> 
> But I get this:
> 
> 
> {
> id: 1,
> division_id: 1,
> name: "subdivision1",
> division: {
> id: 1,
> organization_id: 1,
> name: "division1",
> organization: {
> id: 1,
> name: "organization1",
> divisions: [/* ..list of all the other divisions.. */]
> },
> subdivisions: [/* ..list of all the other subdivisions.. */]
> }
> }
> 
> 
> How can I remove the subdivisions and divisions from returned data using
> Doctrine?
> 
> Because I only need the subdivision, the division it belongs to and the
> organization the division belongs to. And listing all the tree takes a huge
> amount off data and time, while I don't need it all.


-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to