Foreing key is not the id but the "slug" how to change?


I have an a API that is sending out this output for a model:

    "uuid": "05bc38ee-fecd-47d9-88b4-7885492dc520",
    "name": "My Custom Iris [*]",
    "id": 218,
    "userId": 219,
    "vehicleType": "quadcopter",
    "viewPrivacy": "DEFAULT",
    "controlPrivacy": "DEFAULT",
    "missions": [
            "id": 11471,
            "notes": "b646c8ff-0955-4cb4-8167-f3fad4a97667.bin",
            "isLive": false,
            "viewPrivacy": "DEFAULT",
            "vehicleId": 218,
            "maxAlt": 36.45,
            "maxGroundspeed": 24.63,
            "maxAirspeed": 0,
            "maxG": 0,
            "flightDuration": 445.4280002117157,
            "latitude": 32.7628211,
            "longitude": -117.2138655,
            "softwareVersion": "V3.2-rc2",
            "softwareGit": "2f4af05f",
            "createdOn": "2014-07-04T20:57:48Z",
            "updatedOn": "2015-01-05T22:04:22Z",
            "summaryText": "San Diego, California, United States",
            "mapThumbnailURL": ",32.7628,2)/-117.2139,32.7628,2/140x100.png",
            "viewURL": "",
            "vehicleText": "My Custom Iris [*]",
            "userName": "mrpollo",
            "userAvatarImage": "",
            "numParameters": 378,
            "vehicleType": "quadcopter"
    "createdOn": "2014-06-04T16:08:03Z",
    "updatedOn": "2015-01-25T09:24:01Z",
    "summaryText": "My Custom Iris [*]",
    "userName": "mrpollo"

my model is this:

Droneshare.Vehicle = DS.Model.extend({
  uuid: DS.attr(),
  name: DS.attr(),
  userId: DS.attr('number'),
  user: DS.belongsTo('user', { async: true }),
  manufacturer: DS.attr(),
  vehicleType: DS.attr('string', {defaultValue: ''}),
  autopilotType: DS.attr('string', {defaultValue: ''}),
  viewPrivacy: DS.attr(),
  controlPrivacy: DS.attr(),
  missions: DS.hasMany('mission'),
  createdOn: DS.attr('date'),
  updatedOn: DS.attr('date'),
  summaryText: DS.attr()

I have a model for user also:

Droneshare.User = DS.Model.extend({
  login: DS.attr(),
  fullName: DS.attr(),
  isAdmin: DS.attr('boolean'),
  avatarImage: DS.attr(),
  profileUrl: DS.attr(),
  emailVerified: DS.attr('boolean', {default: false}),
  needNewPassword: DS.attr('boolean', {default: false}),
  defaultViewPrivacy: DS.attr(),
  defaultControlPrivacy: DS.attr(),
  vehicles: DS.hasMany('vehicle'),
  hullId: DS.attr()

When I load a vehicle this is the url /api/v1/vehicle/218 but for users it doesn’t use id it gets them by a string /api/v1/user/mrpollo.

How can i change this so that it knows not to ask for /api/v1/user/:id but instead /api/v1/user/:loginName ?


Check out the buildURL hook in the adapter and use it to replace id with name.

Hope this helps.


How do i deal with Vehicle creating a record with id == loginName?


Sorry, but do not understand your question. Can you be a little more specific and perhaps enlighten me with some more example code illustrating what you intend to do?