user1236048
user1236048

Reputation: 5602

Bi-Directional References are always fetched Doctrine MongoDB

Symfony2 Project with Doctrine MongoDB ODM:

I have the following documents:

User

referenceOne:
    my_buddy:
        targetDocument: Buddiness #(just an example)
        mappedBy: from_user
        simple: true
    buddy_with_me:
        targetDocument: Buddiness
        mappedBy: to_user
        simple: true

Buddiness

referenceOne:
    from_user:
        targetDocument: User
        simple: true
        inversedBy: my_buddy
    to_user:
        targetDocument: User            
        simple: true
        inversedBy: buddy_with_me

On every authenticated request I have 2 extra queries:

db.Buddiness.find({ "from_user": ObjectId("...") }).sort([ ]).limit(1).limit();
db.Buddiness.find({ "to_user": ObjectId("...") }).sort([ ]).limit(1).limit();

How can I get rid of these 2?

Upvotes: 0

Views: 392

Answers (1)

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52493

Usually doctrine should use lazy-loading by default.

But i think you can find the answer here.

Remove the mappedBy attribute.

Upvotes: 2

Related Questions