Reputation: 171
I am migrating my LoopBack 3 application to LoopBack 4. in lb3 application i was using embeds one and embeds many feature in my model but unable to find same relation in lb4. By the documentation. it has yet to be implemented. Is the documentation outdated or is it not available? And is there a workaround?
Upvotes: 1
Views: 362
Reputation: 105
It cannot see in the relations when you try to add. But in this issue they presume they fixed it. https://github.com/strongloop/loopback-next/issues/2130
Here is the usage example.
@model()
export ExampleMainClass extends Entity{
@property({
type: 'string',
id: true,
generated: true,
})
id: string;
@property()
key: ExampleSubClass;
}
@model()
class ExampleSubClass{
@property({
type: 'string',
id: true,
generated: true,
})
id: string;
@property({
type: 'string',
required: true,
})
name: string;
}
Create a model and than inside of that model class write your sub module. And add that as a property to your main module. Then it will be okay.
Upvotes: 1
Reputation: 1585
No, EmbedsOne
and EmbedsMany
relations are not implemented at the moment. The focus is currently on implementing and improving SQL relations.
A workaround is to use the HasOne
and HasMany
relations. However, it is not officially supported by StrongLoop.
Upvotes: 2