user9386959
user9386959

Reputation:

How to create one to many relationship using Liferay service builder

I need to define an one-to-many relationship between my custom entity and a Liferay default entity DDMFormInstance. So one MyCustomEntity could have many DDMFormInstance's. How can I do it?

Upvotes: 2

Views: 1437

Answers (2)

Kan Zhang
Kan Zhang

Reputation: 121

André's answer works by repurposing a many-to-many relationship as a one-to-many relationship. The challenge here is that DDMFormInstance is an out of the box Liferay entity, you cannot add a foreign key to it for the one-to-many relationship. André's answer is the easiest solution. You define a many-to-many relationship in the service.xml using mapping-table, then make it behave as one-to-many relationship in your MyCustomEntityLocalServiceImpl class.

Upvotes: 1

André
André

Reputation: 172

you can define collection style columns; furthermore you will need a mapping-table between MyCustomEntity and DDMFormInstance and also remember that service-builder is not an ORM tool, primarily. so there will be a time when out-of-the-box functionalities will end.

<column entity="User" mapping-table="Users_Groups" name="users" type="Collection" />

see more in https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portal/service.xml

Upvotes: 1

Related Questions