掲示板

[SB-6.2] How to create relationships (ForeignKey)

8年前 に Do Kha SI によって更新されました。

[SB-6.2] How to create relationships (ForeignKey)

New Member 投稿: 6 参加年月日: 15/01/23 最新の投稿
Hi all,
I created one service builder with two Entity.
Student and Class.
<entity name="Student" local-service="true" remote-service="false">

<!-- PK fields -->

<column name="studentId" type="long" primary="true" />

<!-- Group instance -->
<column name="classId" type="long" />

<!-- Audit fields -->

<column name="studentName" type="String" />
<column name="birthDay" type="Date" />

<!-- Other fields -->

<column name="description" type="String" />


</entity>
<entity name="ClassX" local-service="true" remote-service="false">

<!-- PK fields -->

<column name="classId" type="long" primary="true" />


<!-- Audit fields -->

<column name="className" type="String" />
<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />

<!-- Other fields -->

<column name="description" type="String" />

</entity>


Please help me. How to add foreign key in Student table in database with column classId reference table Class(classId).
I don't want create table mapping many to many.
And add require className maxlength?
Thank you very much!
thumbnail
8年前 に Alexey Kakunin によって更新されました。

RE: [SB-6.2] How to create relationships (ForeignKey)

Liferay Master 投稿: 621 参加年月日: 08/07/07 最新の投稿
Hi!

Unfortunately there are no way to define FK in Service Builder.
So - you can simple add classId into your Student entity and (for example) finder by classId (it will add index and automatically generate code on persistence layer what will return all students from specified class).

To specify maxlength of some field you need to edit META-INF/portlet-model-hints.xml
for example :

		<field name="className" type="String">
			<hint name="max-length">512</hint>
		</field>
thumbnail
8年前 に David H Nebinger によって更新されました。

RE: [SB-6.2] How to create relationships (ForeignKey)

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Even better answer, you let your DBA create the tables then you just use SB to connect to those existing tables.

The only time you should let SB create tables in your database is when you are building a Market Place plugin.