mardi 18 juillet 2017

How to define model for associations applied only in sub-route?

I have an API server which has a different listing depending on whether it's pulling all users or a single user, e.g.:

GET /users/ returns:

id: 1
name: Name One
username: nameone

id: 2
name: Name Two
username: nametwo

GET /users/1 returns:

id: 1
name: Name One
username: nameone
location: Street 1, City One
devices: [device1, device2]

What happens in the single user listing is that associations are made, i.e. my user table only has id, name, and username, while location and devices are separate tables that have a user_id column`.

How do I go about defining a model like this in Ember? Do I define all fields and leave them empty for the full listing? Or do I need to change my backend API server in order to adapt it to how Ember works (not ideal)? Ideally, I want to conform my Ember model to the data I'm pulling from the API server, rather than to what's in the database, if that makes sense at all.

Thanks for your time!




Aucun commentaire:

Enregistrer un commentaire