[Proposal] Add embedsMany relationship to Eloquent Model #137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request come from code that we are using in our Laravel projects. Because this package is not made to rewrite Eloquent, MongoDB specificities are generally not yet implemented. But the main difference, for web development, with a standard SQL driver is the ability to embed documents inside other ones.
We can do that with this package but only with manual data manipulations or quite a lot of custom code. That's why I have wrote an EmbedsMany class in order to deal with this specificity with a high level of abstraction.
In order to keep the spirit of this package, I tried to keep it as close as I can of Eloquent syntax. For example, the three lines below are exactly the same for a
hasMany
relationship than for aembedsMany
relationship :I also add several others methods that are basically shorthand to do the same things with raw data, with array of related models and without persistence. You can find that in the test cases.
The main difference from SQL Eloquent relationship is that this relationship is not, in fact, a query but directly an array of data. That's why I had to wrote an other relation parent class :
EmbeddedRelation
.I just worked on adding an embedded model and retrieve the list of this models. More work could be done (method
remove
ordelete
, test edge cases...) but I want your opinion about that before.What do you think about the idea, if we keep it simple and close to Eloquent syntax ? What do you think about the implementation (method naming, number of shorthand, architecture...) ?