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?

- 172
- 13
2 Answers
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

- 172
- 13
-
@VlSh .. could you post the service.xml ,, it´s essential parts ? the trick in using the liferay entities is using the
tag , the hard part is finding his package-path – André Jan 05 '19 at 20:48 -
About finding the package path: the hint from the DTD (https://docs.liferay.com/ce/portal/7.0-ga4/definitions/liferay-service-builder_7_0_0.dtd.org.html) is "com.liferay.portal.Organization" in case of Organization. In general: Search for the service.xml of the referenced entity on Github and find the package path there. (for example for AssetCategory the service.xml is https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portlet/asset/service.xml and it states api-package-path="com.liferay.asset.kernel") – Geert Jun 20 '19 at 15:00
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.

- 111
- 2
- 4