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

Indexes not created when embedding a document using mixed document types #1135

Closed
bicatu opened this issue Jun 11, 2015 · 12 comments
Closed
Assignees
Milestone

Comments

@bicatu
Copy link
Contributor

bicatu commented Jun 11, 2015

According to the user manual when I specify the indexes on a embedded document it will be created when persisting the main document.

It is not happening when the embedded document type varies.

To reproduce
Main Document Entity

/**
 * @ODM\Document
 */
class Document
{
    /**
     * @var string Id
     * @ODM\Id
     */
    private $id;

    /**
     * @ODM\EmbedOne(discriminatorField="type")
     */
    private $embedded;

    // setters and getters
}

First embedded type

/**
 * @ODM\EmbeddedDocument
 */
class Embedded1
{
    /**
     * @ODM\Date
     * @ODM\Index
     */
    private $timestamp;

    // setters and getters
}

test code

$document = new Document();
$embedded = new Embedded1();
$embedded->setTimestamp(new \DateTime());
$document->setEmbedded($embedded);

$dm->persist($document);
$dm->flush();
$sm = $dm->getSchemaManager();
$sm->ensureIndexes();

When using find the document and the embedded data has been saved but the getIndexes does not show anything other than the _id.

If I update the annotation to mention targetDocument the index gets created normally.

@malarzm
Copy link
Member

malarzm commented Jun 11, 2015

@bicatu if you want indexes for embedded documents to be created you have to provide targetDocument or discriminatorMap or otherwise ODM doesn't know what can be embedded and what indexes should be created. Feel free to reopen if something is unclear :)

@malarzm malarzm closed this as completed Jun 11, 2015
@bicatu
Copy link
Contributor Author

bicatu commented Jun 11, 2015

Hi @malarzm it is clear even though I do not agree per se. The field type tell it what class to use for the embedded document and in the class I do have the indexes. Hence in my opinion there is a way of achieving the same functionality as when we have when we statically map the document.

May I suggest that if this is not a feature request at least the documentation on the indexes page is updated to make this limitation clear.

@malarzm malarzm reopened this Jun 11, 2015
@malarzm
Copy link
Member

malarzm commented Jun 11, 2015

The field type tell it what class to use for the embedded document

@bicatu what field type are you referring to?

    /**
     * @ODM\EmbedOne(discriminatorField="type")
     */
    private $embedded;

@bicatu
Copy link
Contributor Author

bicatu commented Jun 11, 2015

When I am persisting the document (with its embedded sub-document) I have the entity and the discriminatorField which contains the class name of that embedded document.

From that name I have the definition, hence the index annotation. Is this clear?

@malarzm
Copy link
Member

malarzm commented Jun 11, 2015

As far as I am concerned ODM is not checking in database what embedded documents are used in main documents, only metadata is used for that.

According to the user manual when I specify the indexes on a embedded document it will be created when persisting the main document.

Can you please paste a link to that part of docs?

@bicatu
Copy link
Contributor Author

bicatu commented Jun 12, 2015

Hi http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/indexes.html is the one that mentions at the section "Embedded Indexes" about the creation of the indexes for embedded documents.

And http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/embedded-mapping.html#mixing-document-types for the embedded documents.

So there is no mention that "in order to create the indexes you have to specify the targetDocument or the discrimitatorMap on the Document"

@malarzm malarzm added this to the 1.0.0 milestone Jun 12, 2015
@malarzm
Copy link
Member

malarzm commented Jun 12, 2015

Indeed we should amend the documentation (or would you mind making a PR?). Thank you for the report!

@bicatu
Copy link
Contributor Author

bicatu commented Jun 12, 2015

I can make the PR. Is there any reference on the proper procedure to do so - update the documentation ?

@malarzm
Copy link
Member

malarzm commented Jun 12, 2015

I don't think we have a procedure for that - you just open a PR with needed changes referencing this issue, we review that, maybe ask for amendments and merge afterwards :)

@bicatu
Copy link
Contributor Author

bicatu commented Jun 13, 2015

I created a pull request.

@jmikola
Copy link
Member

jmikola commented Aug 18, 2015

See #1143.

@jmikola
Copy link
Member

jmikola commented Aug 18, 2015

#1143 has been merged.

@jmikola jmikola closed this as completed Aug 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants