Skip to content

Feedback please (v3) #434

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
jenssegers opened this issue Feb 28, 2015 · 6 comments
Closed

Feedback please (v3) #434

jenssegers opened this issue Feb 28, 2015 · 6 comments

Comments

@jenssegers
Copy link
Contributor

I'm having a few issues with the current implementation of embedded models. In the beginning, it seemed like a really cool idea to add it to this library, but because of this, a lot of custom code had to be added to allow users work with these embedded models in a flexible way.

Currently I'm considering a complete rewrite of the embedded models using model observers/events. These event listeners will then trigger the save method of all parent models, instead of trying to intercept it in the model class. I have no idea if it will work eventually, but it seems like a more practical implementation that is less prone to bugs. I will be trying out a prototype today, if anyone has some additional ideas, please reply below :)

@jenssegers
Copy link
Contributor Author

I just pushed a first change to the develop brach; from now on, if you want to use the "hybrid relations" between mongodb and mysql, you no longer have to extend a special class, but you can use a HybridRelations trait instead.

@jenssegers jenssegers changed the title Feedback please Feedback please (v3) Feb 28, 2015
@jenssegers
Copy link
Contributor Author

Because this will probably be a new (breaking) major version. I decided to move the Model class to Jenssegers\Mongodb\Eloquent\Model to respect the original Laravel folder structure.

@jenssegers
Copy link
Contributor Author

It seems that the event based approach might not work out of the box. Observers are registered to all instances of a certain model class, not one instance in particular. Either I modify the model class to allow for instance observers, or I search for a different solution.

@alexandre-butynski
Copy link
Contributor

Hi Jens, few words about embedded relations and objects :

First, embed objects in MongoDB is one of the key features for a lot of web application. The ability of easily saving complex and changing data structures is probably the main reason for us for using MongoDB.

Second, you are right, there are few improvements that could be done in this part of the package. Someones are listed in the issues #310 or #387 for example but there are also some ambiguous things like when you do Comment::create(array()) when Comment is an embedded model. This can be particularly surprising for beginners.

Third, I have not take time to look at your first try but I know that working with events can be really tricky in Laravel (even if it seems to be improved in L5). Why not create an EmbeddedModel class or an EmbeddedModelTrait ?

I would have liked to have more time to contribute but, at least, I can be in the corner next days to take a look at what will be done.

@jenssegers
Copy link
Contributor Author

I don't think a specific trait for embedded models would be the way to go. For example, you could have objects embed each other; eg. a user embedding another user as parent/brother.

I completely started embedded models from scratch in the current develop branch. But operations on embedded models are not working yet. There's still a lot of work to be done :)

@spawn-guy
Copy link

i would like to monitor the progress over here. as i started using the embedMany, but it gives me weird results. Like, a separate "table" in the database.

so i dropped the idea and went for dot-notation :/ and now i'm fixing dot-Dates in attributesToArray and dot-enabled syncOriginalValue (as it doesn't work with ->increments(something.sometingelse)).

am i doing something not in a correct way? is there an example to embedOne, that embedMany?

also i'm interested in GeoJSON, but this is for later

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

No branches or pull requests

3 participants