Modify (move) relationships

0 views
Skip to first unread message

pedrobl

unread,
Nov 28, 2009, 10:14:11 PM11/28/09
to transfer-dev

Hi!

I have an organisation object with two o2m relations person and
projects. In order to eliminate duplicates, I need to move the related
persons and projects from one organisation to another.

Is there an easy way to do this with transfer? I use two linking
tables org_person, and org_project to store the relation between them,
and also stores other information like the person's role (staff,
contact, administrator, etc...), or the initial and end date for the
relation. I'd like to move those relationships unchanged, just to move
them from organisation A to organisation B.

In SQL this would be trivial to do by just updating the organisation
FK from organisation A, to organisation B in the org_person table.

I'd like to avoid looping through the org_person structure to modify
each org_person.OrgId from one organisation to the other, as I'd need
to create the organisation objects.

Can this be achieved in one shot? Something like:

<cfset org1persons = org1.getPersonsStruct() />
<cfset org2persons = org2.getPersonsStruct() />
<cfset StructAppend(org1persons, org2persons, true) />
<cfset org1.setPersons(org1persons) />

TIA!

Pedro.

Sean Coyne

unread,
Nov 30, 2009, 8:02:03 AM11/30/09
to transfer-dev
depends on your Transfer configuration but most likely you would do
something like:

<cfset person.setParentOrganization(org) />

where person is your person object and org is your organization
object. Note that this will only work if you have specified a one to
many in the organization configuration and that you called
organizations "Organization" in your transfer config.

Sean

pedrobl

unread,
Nov 30, 2009, 5:05:49 PM11/30/09
to transfer-dev

Sean,

Thanks for the reply! Unfortunately, the organisations and persons are
not related directly. This is my transfer.xml file:

<package name="dc">
<object name="Organisation" table="organisations">
<id name="OrgId" type="string" generate="false" column="ORG_ID" />
<property name="CommonName" type="string" nullable="false"
column="COMMON_NAME" />
...
<onetomany name="OrgPerson" lazy="true">
<link to="dc.OrgPerson" column="ORG_ID" />
<collection type="struct">
<key property="OrgPersonId"/>
</collection>
</onetomany>
</object>

<object name="Person" table="DC_PERSONS">
<id name="PersonId" column="PERSON_ID" type="string"
generate="false" />
<property name="FirstName" type="string" nullable="false"
column="FIRST_NAME"/>
<property name="FamilyName" type="string" nullable="false"
column="FAMILY_NAME"/>
...
<onetomany name="OrgPerson" lazy="true">
<link to="dc.OrgPerson" column="PERSON_ID" />
<collection type="struct">
<key property="OrgPersonId"/>
</collection>
</onetomany>
</object>

<object name="OrgPerson" table="DC_ORG_PERSON" >
<id name="OrgPersonId" column="ORG_PERSON_ID" type="string"
generate="false" />
<property name="PersonId" type="string" nullable="false"
column="PERSON_ID" />
<property name="OrgId" type="string" nullable="false"
column="ORG_ID" />
<property name="Role" type="string" nullable="false" column="ROLE" /
>
<property name="StartDate" type="date" nullable="true"
column="START_DATE" />
<property name="EndDate" type="date" nullable="true"
column="END_DATE" />
</object>

As I need to have many roles per person and organisation, i.e. a many-
to-many relation between organisations and persons with extra data in
the linking table.

I'd like to append the OrgPerson Struct that belongs to Organisation
2, to the Organisation 1 that replaces it. Something like:

<cfset org1persons = org1.getPersonsStruct() />
<cfset org2persons = org2.getPersonsStruct() />
<cfset StructAppend(org1persons, org2persons, true) />
<cfset org1.setPersonsStruct(org1persons) />

I'd like to avoid looping through all org2persons struct members. Is
your commendation something like the following?

<cfloop collection="#org2persons#" item="OrgPersonId" >
<cfset orgpersons[OrgPersonId].setParentOrganization(org1) />
</cfloop>

TIA,

Pedro.

pedrobl

unread,
Dec 18, 2009, 11:39:25 AM12/18/09
to transfer-dev

I guess there's no way to do this easily with transfer... As I said in
my first email, right now you need to loop through all relations, and
set each foreign to the other one.

From my point of view, this is unacceptable, specially when there's
such a better alternative, the good old UPDATE that gets this done in
one SQL sentence. :(

I have tried the looping, and it has a horrible performance.

Happy holidays everyone! :)

Pedro.

Matt Quackenbush

unread,
Dec 18, 2009, 11:47:12 AM12/18/09
to transf...@googlegroups.com
I have not read through the entire thread, but based upon your
statement about SQL vs. a loop I would say just do it in SQL and then
discard the affeced objects from the Transfer cache.

HTH

> --
> Before posting questions to the group please read:
> http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer
>
> You received this message because you are subscribed to the Google Groups "transfer-dev" group.
> To post to this group, send email to transf...@googlegroups.com
> To unsubscribe from this group, send email to transfer-dev...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/transfer-dev?hl=en

Mark Mandel

unread,
Dec 18, 2009, 6:32:03 PM12/18/09
to transf...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages