I have Address model:
Address extends Entity {
@property({
type: 'number',
id: true,
generated: true,
mysql: {
"columnName": "m_id"
}
})
mId?: number;
@property({
type: 'number',
mysql: {
"columnName": "m_belong_to_id"
}
})
mBelongToId?: number;
@property({
type: 'GeoPoint',
required: true,
mysql: {
"columnName": "m_geo_point"
}
})
mGeoPoint: GeoPoint;
}
I try this query:
let nearByAddressList = await this.addressRepo.find({
where: {
and: [
{
mGeoPoint: {
near: location,
maxDistance: this.maxDistance,
unit: this.unit
}
}
]
}
});
and the console show me the bug: _model.toObject() is not a function on file node_modules/@loopback/repository/dist8/src/repositories/legacy-juggler-bridge.js:160_
If I remove the _where_ filter, the code run normally.
I checked the code and couldn't find _near_ properties on Where filter class.
Can I use _near_ in _where_ filter on Lp4 now?
Query run normally with _near_ in query.
_See Reporting Issues for more tips on writing good issues_
Hi @hosiduy, could you please provide us with a sandbox to reproduce this issue?
Hi @shimks,
I don't know how to create a sandbox for you to create this issue. Please help to show me how to make one.
I did fix this problem by change the code in file: _node_modules/dist8/src/repositories/legacy-juggler-bridge.js_ -> toEntity(model) function.
Before change:
toEntity(model) {
return new this.entityClass(model.toObject());
}
My change:
toEntity(model) {
let check;
if (!model) return null;
if (typeof model.toObject === 'function') {
check = new this.entityClass(model.toObject());
} else {
check = new this.entityClass(model);
}
return check;
}
Hope this help.
I was able to reproduce this issue, thanks. Looks like we'll need to check whether the model we get back in toEntity is an instance of model or not. Would you like to make a PR with the change you've made?
Related to #1378.
cc @raymondfeng @bajtos
Okay @shimks , I will make a PR with the change I've made.
@hosiduy Are you still interested / able to work on this issue. I know you forked the repo, once you have made the necessary changes you will have to Open a PR by clicking the Pull Request link within your forked repo.

Hi, any news? I'm getting the same issue. Cannot use near filter.
Please refer to https://github.com/strongloop/loopback-next/issues/1981 for updates discussions.
Please note that this issue does not require GeoPoint support to be landed. Here, we just need to fix toEntity method in our repository implementation.
@hosiduy @susannaHayrapetyan We've fixed this recently in juggler. Please try upgrading your dependencies so that you get [email protected] and the issue should be resolved. Feel free to re-open if that's not the case.
Most helpful comment
@hosiduy @susannaHayrapetyan We've fixed this recently in juggler. Please try upgrading your dependencies so that you get
[email protected]and the issue should be resolved. Feel free to re-open if that's not the case.