create lucid relation with join and custom select not work in eager loading #1749
Replies: 2 comments 2 replies
-
As I try to reproduce the bug. found when the eager load method is call it fetch the data but after that when try to group the data the data would be drop becase it should not defined and But is there any solution for resolve this? |
Beta Was this translation helpful? Give feedback.
-
@thetutlage In the I'm changing the /**
* Takes an array of related instances and returns an array
* for each parent record.
*
* @method group
*
* @param {Array} relatedInstances
*
* @return {Object} @multiple([key=String, values=Array, defaultValue=Null])
*/
group (relatedInstances) {
const transformedValues = _.transform(relatedInstances, (result, relatedInstance) => {
// add this part for find the table foreign key
let foreignKey = this.foreignKey
if(foreignKey !== undefined)
foreignKey = String(foreignKey.split('.').splice(-1, 1))
const foreignKeyValue = relatedInstance[foreignKey]
const existingRelation = _.find(result, (row) => row.identity === foreignKeyValue)
/**
* If there is already an existing instance for same parent
* record. We should override the value and do WARN the
* user since hasOne should never have multiple
* related instance.
*/
if (existingRelation) {
existingRelation.value = relatedInstance
return result
}
result.push({
identity: foreignKeyValue,
value: relatedInstance
})
return result
}, [])
return { key: this.primaryKey, values: transformedValues, defaultValue: null }
} |
Beta Was this translation helpful? Give feedback.
-
I have a
Product
class with the relation like belowI'm checking the query and this is fine and have no problem.
but when I'm calling this relation for eager loading. it return
null
like below querybut If fetch the price it return the result like below
what is the problem and how should I solve this
Beta Was this translation helpful? Give feedback.
All reactions