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

Questions: update hasMany extra_fields? AS command? #197

Closed
m13 opened this issue Jun 11, 2013 · 6 comments
Closed

Questions: update hasMany extra_fields? AS command? #197

m13 opened this issue Jun 11, 2013 · 6 comments

Comments

@m13
Copy link

m13 commented Jun 11, 2013

  1. Is there any way to change only the value of a hasMany table (extra_fields) of a set of values? I think that delete and re-add the rows each time kills the performance.

  2. Is there any way to change the name of the results with the ORM? (like the AS command in mysql)

Thankss!

@m13
Copy link
Author

m13 commented Jun 11, 2013

I think that this line:

data[association.mergeAssocId] = Association.id;

should be changed to data[association.mergeAssocId] = Association[association.mergeAssocId];

If your ids are not called "id", you have problems :-/. Could you verify and merge?

@dresende
Copy link
Owner

You're probably right, I'm a little tired but I'm going to change it and check the unit tests.

@dresende
Copy link
Owner

I think what you probably want is this:

data[association.mergeAssocId] = Association[association.model.id];

dresende added a commit that referenced this issue Jun 11, 2013
@dresende
Copy link
Owner

About your questions:

  1. You should be able to fetch an instance (record), get the association with the extra data, change it and just hit instance.save(). If it doesn't work, try overwriting some property of the model (even if it's with the same value).
Model.get(123, function (err, Instance) {
    Instance.getAssoc(function (err, Assoc) {
        Assoc.extra.whatever = newvalue;
        Assoc.prop = Assoc.prop;
        Assoc.save();
    });
});
  1. I don't have any plans for it. Do you have a use case example?

@m13
Copy link
Author

m13 commented Jun 12, 2013

  1. I used your code, but I had to use a for() iteration over the elements of Assoc. But it means that I'm doing a query for each element. Example:
    141 Query UPDATE notification_user SET seen = true WHERE user_id = 1 AND notification_id = 1
    141 Query UPDATE notification_user SET seen = true WHERE user_id = 1 AND notification_id = 2
    When I would like:
    141 Query UPDATE notification_user SET seen = true WHERE user_id = 1 AND notification_id IN (1,2)
    The same happens when you're working with a INSERT. (I'm researching about the performance)

  2. With the fix, I don't need it anymore :) Thank you very much!

@dresende
Copy link
Owner

Doing those kind of changes would require maybe to use ChainInstance but that will probably be hard since this is just one use case, there are others with possibly different update queries.

@m13 m13 closed this as completed Jun 14, 2013
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

2 participants