Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline field denormalization for Reference* mapping #613

Open
j opened this issue Jun 10, 2013 · 6 comments
Open

Inline field denormalization for Reference* mapping #613

j opened this issue Jun 10, 2013 · 6 comments
Labels
Milestone

Comments

@j
Copy link
Contributor

j commented Jun 10, 2013

Think of the following two documents:

<?php

/** @Document() */
class Survey {
    /** @Id() */
    public $id;

    /** @ReferenceMany(targetDocument="Question", embedFields={"question"}) */
    public $questions;
}

/** @Document() */
class Question {
    /** @Id() */
    public $id;

    /** @String() */
    public $question;
}

The mongo stored documents for surveys would look like:

{
    "_id": "...",
    "questions": [
        { "$ref": "...", "$id": "...", "$db": "...", "question": "Is ODM awesome?" },
        { "$ref": "...", "$id": "...", "$db": "...", "question": "Isn't this such a great feature?!" },
    ]
}

So that if you do the following, no extra finds will be triggered unless the field wasn't embedded in the referenced document data:

<?php

$questions = [];
foreach ($surveyRepository->find("...")->getQuestions() as $question) {
    $questions[$question->getId()] = $question->getQuestion();
}

Updates to the question may cascade unless configured to not do so, or the other way around. In most of my cases, a cascade can occur.. but if someone happens to use this feature on an active database with many records, then shit can hit the fan!

It'd be easy to create a document and manage it as if it were it's own document and just associate that to one thing and be embedded. I tend to use it this way in many cases... thus would limit many finds.

Another thing that can also solve this problem is to introduce caching, but that's another topic.

@tecbot
Copy link

tecbot commented Jun 10, 2013

I have implemented this for a long time for sharding: see #325
generally it makes the same what you explain here, but it's incomplete and need some rewrites to fit upstream.

@malarzm malarzm added the Idea label Nov 4, 2015
@alcaeus alcaeus added this to the 1.x milestone Mar 14, 2016
@alcaeus
Copy link
Member

alcaeus commented Mar 14, 2016

As mentioned by @tecbot, this makes sense when using a sharded setup. I'll be revisiting this once #1349 is finished (since that involves some changes to the DBRef logic used by ODM)

@alcaeus
Copy link
Member

alcaeus commented Dec 22, 2017

I've started working on this a while ago (see #1527), but this won't make much sense until we've got the new array update operators that allow us to keep the data in sync (if the user so wishes).

@alcaeus alcaeus modified the milestones: 1.x, 2.x Dec 22, 2017
@alcaeus alcaeus removed this from the 2.x milestone Aug 5, 2021
@stale
Copy link

stale bot commented Sep 6, 2021

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Issues that have not seen any activity in 30 days label Sep 6, 2021
@stale stale bot closed this as completed Apr 18, 2022
@malarzm malarzm added this to the 2.x milestone Apr 18, 2022
@malarzm malarzm reopened this Apr 18, 2022
@stale stale bot removed the Stale Issues that have not seen any activity in 30 days label Apr 18, 2022
@techbelle
Copy link

@alcaeus can we 'un-stale-ify' this ? :)

@alcaeus
Copy link
Member

alcaeus commented Nov 13, 2023

@techbelle this is part of the 2.x milestone, so it won't be marked as stale again. That said, I haven't managed to make any progress on this or on the previously mentioned update operators, which IMO should take precedence over this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants