Strongloop - hasOne relation

dominik

I am having some trouble with setting up a hasOne relation, which probably comes from me understanding the relation wrongly?

I have 2 Models, one user model, and one location model. What I want to add now is a relation between user and location, meaning a user has a current location. But if I set up a hasOne relation on the user model with the location, I end up with a userId property in the location. But this is completely wrong, since several users can have the same current location, so the user model should store the location id, not the location the user id. So how can I achieve what I want, so that I can afterwards query the user and include the current location?

I can of course add a property to the user and store the id of the location there, but then I can't as easily include the location in a user request. So I would prefer using relations to achieve this.

Overdrivr

Your problem is a bit unclear, given the comments of Brian's post, but if you absolutely need Users to share a given set of locations then you would be better off using User belongsTo location.

This will create a locationId field in User, and you will be able to GET api\Users\{userId}\location

Eventually, you can set a location hasMany User to retrieve from a given location all the users in there

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Undefined property in an "hasOne" relation

From Dev

Table hasOne relation not being created

From Dev

Overriding Relation Remote Method In Strongloop Loopback

From Dev

Only get String from hasOne Relation

From Dev

yii2 hasOne relation work wrong

From Dev

yii2 hasOne relation work wrong

From Dev

Only get String from hasOne Relation

From Dev

orderBy in hasOne relation doesn't work

From Dev

hasOne relation on same model not working in laravel 5.6

From Dev

CakePHP find items with hasOne Model relation that have no associated item

From Dev

How do I create a correct hasOne relation between two objects with loopback and angular

From Dev

How do I create a correct hasOne relation between two objects with loopback and angular

From Dev

hasOne filtered by value of previous hasOne?

From Dev

Cannot connect to StrongLoop PM using StrongLoop Arc

From Dev

Eloquent Relation - Relation of a Relation

From Dev

Eloquent Relation - Relation of a Relation

From Dev

No Ports Assigned to Strongloop App

From Dev

Strongloop only binds to 127.0.0.1

From Dev

Implementing Q with Strongloop Loopback

From Dev

Persist Users in Strongloop Loopback

From Dev

Using Push Notications in Strongloop

From Dev

StrongLoop Loopback Yeoman Angular

From Dev

Meteor app with StrongLoop

From Dev

Stop detached strongloop application

From Dev

Createmany in Strongloop Loopback

From Dev

Can not install strongloop

From Dev

Strongloop: currentContext not available in middleware?

From Dev

Using Push Notications in Strongloop

From Dev

Using Docker/Fig with StrongLoop