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

Complex objects as attrs don't get marked dirty #9

Open
rschmukler opened this issue Jun 26, 2014 · 1 comment
Open

Complex objects as attrs don't get marked dirty #9

rschmukler opened this issue Jun 26, 2014 · 1 comment

Comments

@rschmukler
Copy link
Member

when setting nested properties or mutating arrays

@rschmukler rschmukler changed the title Complex objects as attrs don't get updated Complex objects as attrs don't get marked dirty Jun 26, 2014
@paglias
Copy link

paglias commented Jul 5, 2014

For arrays probably the best solution is:

  1. Include a method to manually set a field as dirty like mongoose's markModified
  2. Proxy all the mutation methods on array, creating a custom class with methods like push, pop , ... that updates a stored private array and uses the necessary MongoDB operation http://docs.mongodb.org/manual/reference/operator/update-array/

This is how mongoose does it https:/LearnBoost/mongoose/blob/3.8.x/lib/types/array.js#L27

For nested properties I suppose that when there is a defined set of sub properties in the schema like:

Model.attr('obj', {
    sub1: Date,
    sub2: String
})

(Or another syntax given that the second argument can be used for passing options.) And then transform each sub property using a getter and a setter, for objects without a defined set of sub property I think that the only thing that you can do is using a method like markModified to be used manually.

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

2 participants