不要怂,就是干,撸起袖子干!

Commit acce21d4 by Jan Aagaard Meier Committed by Mick Hansen

fix(btm): Expose belongs to many getter similar to other associations (#6552)

1 parent 2ae4d9a8
Showing with 10 additions and 5 deletions
...@@ -421,12 +421,10 @@ class BelongsToMany extends Association { ...@@ -421,12 +421,10 @@ class BelongsToMany extends Association {
return this; return this;
} }
injectGetter(obj) { get(instance, options) {
const association = this;
obj[this.accessors.get] = function(options) {
options = Utils.cloneDeep(options) || {}; options = Utils.cloneDeep(options) || {};
const association = this;
const through = association.through; const through = association.through;
let scopeWhere; let scopeWhere;
let throughWhere; let throughWhere;
...@@ -444,7 +442,7 @@ class BelongsToMany extends Association { ...@@ -444,7 +442,7 @@ class BelongsToMany extends Association {
if (Object(through.model) === through.model) { if (Object(through.model) === through.model) {
throughWhere = {}; throughWhere = {};
throughWhere[association.foreignKey] = this.get(association.source.primaryKeyAttribute); throughWhere[association.foreignKey] = instance.get(association.source.primaryKeyAttribute);
if (through.scope) { if (through.scope) {
_.assign(throughWhere, through.scope); _.assign(throughWhere, through.scope);
...@@ -480,6 +478,13 @@ class BelongsToMany extends Association { ...@@ -480,6 +478,13 @@ class BelongsToMany extends Association {
} }
return model.findAll(options); return model.findAll(options);
}
injectGetter(obj) {
const association = this;
obj[this.accessors.get] = function(options) {
return association.get(this, options);
}; };
obj[this.accessors.count] = function(options) { obj[this.accessors.count] = function(options) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!