-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Invalid query bindings on relation belongsTo #165
Conversation
…hasOne without null value in foreign key
src/Lucid/Relations/BelongsTo.js
Outdated
@@ -32,7 +32,13 @@ class BelongsTo extends BaseRelation { | |||
* @return {Array} | |||
*/ | |||
mapValues (modelInstances) { | |||
return _.map(modelInstances, (modelInstance) => modelInstance[this.primaryKey]) | |||
const values = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be done in one line using the _.transform
method of lodash. I don't like the idea of intermediate variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What u can do is
_.transform(modelInstances, (result, modelInstance) => {
if (modelInstance[this.primaryKey]) {
result.push(modelInstance[this.primaryKey])
}
return result
}, [])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, my knowledge is small in lodash.
I will try use _.transform
and send changes
src/Lucid/Relations/BelongsTo.js
Outdated
@@ -32,7 +32,13 @@ class BelongsTo extends BaseRelation { | |||
* @return {Array} | |||
*/ | |||
mapValues (modelInstances) { | |||
return _.map(modelInstances, (modelInstance) => modelInstance[this.primaryKey]) | |||
const values = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What u can do is
_.transform(modelInstances, (result, modelInstance) => {
if (modelInstance[this.primaryKey]) {
result.push(modelInstance[this.primaryKey])
}
return result
}, [])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I send changes, u can see it
src/Lucid/Relations/BelongsTo.js
Outdated
@@ -32,7 +32,13 @@ class BelongsTo extends BaseRelation { | |||
* @return {Array} | |||
*/ | |||
mapValues (modelInstances) { | |||
return _.map(modelInstances, (modelInstance) => modelInstance[this.primaryKey]) | |||
const values = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, my knowledge is small in lodash.
I will try use _.transform
and send changes
This looks better |
Fix for #164