I have an Ember application (with ember data) that is run on a user's machine. There's an API server running on their machine, and one running online. I need to allow users to choose where a model is persisted (the API running on their machine, or the online API). So, two API hosts:
http://localhost:3000
and
http://api.example.com
When a user creates a record, they can set wether they want the record saved locally (through the local API server), or saved online. I persist this choice to a value on the record called dataSource.
So, depending on the record dataSource, I need to set the ember RestAdapter host for the model to the correct value. I understand one can override adapters on a per model basis. For example, I could create a RecordAdapter and manually set the host to a value. However, the host depends on a value in the record, and I'm not sure how to accomplish this with Ember Data, since the rest adapter "host" is a property, not a function.
http://emberjs.com/api/data/classes/DS.RESTAdapter.html#property_host
User flow example:
- User creates new record, chooses the option to store this record locally.
- Record is persisted to localhost.
- User creates a new record, chooses the option to store this record online.
- Record is persisted to http://api.example.com
- Any time a record is saved, updated, deleted, etc, it must check the record dataSource to determine the api host to use in the operation.