mean-expert-official / loopback-sdk-builder

Tool for auto-generating Software Development Kits (SDKs) for LoopBack
Other
399 stars 175 forks source link

How to handle relations #170

Closed MitkoTschimev closed 8 years ago

MitkoTschimev commented 8 years ago

What type of issue are you creating?

Write other if any:

Please add a description for your issue:

Hello,

how can i use relations in the typescript code? Can you give me an example e.g. with "Belongs To"?

Best regard

dmastag commented 8 years ago

Hi @tfiwm You should be able to use the normal loopback relationship filter using include. Just put it inside the function call.

Julian

MitkoTschimev commented 8 years ago

Hi @dmastag

thx for the quick answer :) can you give me a link with an example. This would be great! Thank you very much!

itamar-Cohen commented 8 years ago

Hi,

you can go to the wiki page https://github.com/mean-expert-official/loopback-sdk-builder/wiki/5.-Usage-Examples

and check the getRoom in the real time app

`getRoom(id: any): void {

  this.roomApi.findById(id, {
    include: [
      {
        relation: 'messages',
        scope: { order: 'id DESC' }
      }
    ]
  }).subscribe((room: Room) => {
    this.room = room;
    this.roomApi.onCreateMessages(this.room.id)
                .subscribe((message: Message) => this.room.messages.push(message))
  });

} `

MitkoTschimev commented 8 years ago

thx a lot!

jonathan-casarrubias commented 8 years ago

Hey Guys, Thanks for reaching and jumping in to the question.

I'm glad this is starting to feel like wider community.

Cheers!!! Jon