Skip to content

belongsTo relation #389

Description

@kalko91

HI guys. I have a problem. help me please.

I have API url example this:
PUT /api/mcus/{id}/trailer/{trailerId} Assign MCU device to Trailer

Trailer Model

var Trailer = restmod.model('api/trailers');
        Trailer.mix({
            mcu: { hasOne: 'Mcu'}
        });

Mcu Model

var Mcu = restmod.model('api/mcus');
        Mcu.mix({
            trailer: { belongsTo: 'Trailer'},
        });

Update Mcu model

vm.model = Mcu.$find(1).$then(function(){
                    var trailer = TrailerModel.$find(3).$then(function(){
                         vm.model.trailer = trailer;
                        vm.model.$save(); // url PUT /api/mcus/1
                        vm.model.trailer.$save() // url PUT /api/trailers/3
                    })

In mcu model i have this json

{
   "id":1,
   "deviceId":5336091833,
   "serialNo":"test",
   "ipAddress":"127.0.0.1",
   "trailer":{
      "id":3,
      "title":"Test Trailer",
      "description":"test"
   },
   "sensors":[

   ]
}

Whot I have to do to get this link? // PUT /api/mcus/{id}/trailer/{trailerId}

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions