Skip to content

New Command: make:document #1330

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

Closed
wants to merge 22 commits into from
Closed

Conversation

constantable
Copy link

@constantable constantable commented Jun 28, 2023

New Command: make:document to interactively generate document classes for doctrine/mongodb-odm-bundle

Related issues #320 , #364

@constantable
Copy link
Author

Need help with the MongoDB and ext-mongodb PHP extention setup for AppVeyor.

@constantable
Copy link
Author

Need help with the MongoDB and ext-mongodb PHP extention setup for AppVeyor.

Fixed AppVeyor

@OskarStark
Copy link
Contributor

cc @alcaeus

Copy link
Contributor

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some code feedback below.

What I'm completely missing in this PR is support for embedded documents. For one, this should support creating embedded document classes (which use a different document attribute, have no repository, and can be final), as well as creating embedded relationships in the maker itself. Currently the maker assumes all relationships to be references, which isn't true for ODM. In fact, embedded documents are a core concept in MongoDB, and as such I believe they need to be included in the builder for it to be considered.

@constantable
Copy link
Author

@alcaeus Thank you for code review and suggestions!

Implemented support for embedded documents.
An EmbeddedDocument could be created form scratch if --embedded option specified.

When embeding a class that has the ODM\Document PHP attribute maker will ask should it be transformed to ODM\EmbeddedDocument. Please leave a word what you think about this approach.

@alcaeus
Copy link
Contributor

alcaeus commented Jul 31, 2023

Implemented support for embedded documents. An EmbeddedDocument could be created form scratch if --embedded option specified.

Sounds good!

When embeding a class that has the ODM\Document PHP attribute maker will ask should it be transformed to ODM\EmbeddedDocument. Please leave a word what you think about this approach.

The problem is that anything mapped as document can't be embedded, and anything mapped as embedded document can't be stored as root document in a collection. IMO the smartest choice would be to print an error message and suggest an alternative (e.g. a mapped superclass containing common properties, extended by two separate classes that then add the Document and EmbeddedDocument mappings). Unfortunately, changing a Document to an EmbeddedDocument will break existing functionality if the document is already used in a non-embedded context somewhere. I believe it's fine to explain this problem to the user and letting them solve it themselves before allowing to embed the class.

@constantable
Copy link
Author

Made changes to print the error message.
image

@constantable constantable requested a review from alcaeus August 9, 2023 20:06
@weaverryan
Copy link
Member

Hi there!

I think this is a very cool thing. I have avoided reviewing it because... to be fully honest, I don't want to have to maintain all of the code to make this work. make:entity requires a lot of code and complexity, but I'm ok with it because I use it. But I won't use this command (nothing bad about the ODM! It's just not in my stack).

I would prefer to have this as a 3rd party, independent bundle and to add any new APIs to MakerBundle to make that possible. I would even be cool with adding a fake make:document to MakerBundle that tells you what composer require command to run to get the bundle that actually adds it.

Let me know what you think - and sorry for not talking with you about this sooner - it's always very busy.

Cheers!

@jrushlow jrushlow added the Feature New Feature label Feb 16, 2024
@jrushlow
Copy link
Collaborator

Howdy @constantable - this looks awesome! But I have to agree with @weaverryan on the maintenance burden this would add to maker-bundle. If you need help on getting this going as a 3rd party bundle, please don't hesitate to create an issue, we'll be glad to help.

We love new ideas and the PR's that are created from those ideas, so keep them coming! Thanks...

@jrushlow jrushlow closed this Feb 16, 2024
@TracKer
Copy link

TracKer commented Feb 28, 2024

@constantable It would be really cool if you could organize your code into a separate maker-bundle package

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

Successfully merging this pull request may close these issues.

6 participants