-
Notifications
You must be signed in to change notification settings - Fork 376
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
Is it possible to add a before hook to an association table? #324
Comments
I tried to explore the source and was having difficulty getting into the mind set of the code. It seems to me @ first glance thought that it is not possible to define hooks an association tables. Is the association table though a "Model" object though? If not would it make sense to make it a Model object? That way you can have more control over the handling of data stored on the edge. |
What exactly do you want to do? What do you mean by association table, the 3rd table or the table of the other model? |
I want to add validations to the 3rd tables data ( i believe the term is I took some time to go through the source and it didnt seem that the 3rd |
Yes, I understand. I'll see if I can force a new |
Usage: Person.hasMany("pets", Pet, {
born : Date
}, {
hooks : {
beforeSave : function (props, next) {
// props is { born: ... } or empty {}
// `this` is a reference to the pet being associated
return next();
}
}
}); If no extra properties defined, hook will not pass Person.hasMany("pets", Pet, {}, {
hooks : {
beforeSave : function (next) {
return next(new Error('no associations allowed')); // error example
}
}
}); |
Please test by installing from git: npm install dresende/node-orm2 |
I have defined an hasMany relationship and it works as I would assume it does but for some reason the beforeCreate hook on the association table is not called.
The text was updated successfully, but these errors were encountered: