Ok Mark, thanks for your reply, here's some more details:
DB: MySQL 5.0.67 (Linux)
CF: 8,0,1,195765 (Windows XP)
Transfer: v1.0 stable
This is my DB:
CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8 */;
DROP TABLE IF EXISTS `test`.`contacts`;
CREATE TABLE `test`.`contacts` (
`IDContact` varchar(32) NOT NULL,
`enumType` char(1) NOT NULL,
`name` varchar(80) default NULL,
`address` varchar(50) default NULL,
PRIMARY KEY (`IDContact`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `test`.`representatives`;
CREATE TABLE `test`.`representatives` (
`IDRepresentative` varchar(32) NOT NULL,
`IDPerson` varchar(32) NOT NULL,
`IDOrganization` varchar(32) NOT NULL,
`job` varchar(100) NOT NULL,
PRIMARY KEY (`IDRepresentative`),
CONSTRAINT `FK_Repr_Org` FOREIGN KEY (`IDOrganization`) REFERENCES
`contacts` (`IDContact`),
CONSTRAINT `FK_Repr_Pers` FOREIGN KEY (`IDPerson`) REFERENCES
`contacts` (`IDContact`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
transfer XML now looks like this:
<object name="Contacts" table="contacts">
<id name="IDContacts" column="IDContact" type="string" />
<property name="enumType" type="string" column="enumType" />
<property name="name" type="string" column="name" />
<property name="address" type="string" column="address" />
<onetomany name="repr1">
<link to="Representatives" column="IDPerson" />
<collection type="array"/>
</onetomany>
<onetomany name="repr2">
<link to="Representatives" column="IDOrganization" />
<collection type="array"/>
</onetomany>
</object>
<object name="Representatives" table="representatives">
<id name="IDRepresentatives" column="IDRepresentative" type="string" /
>
<property name="job" type="string" column="job" />
</object>
IDPerson and IDOrganization are left out as properties from object
Representatives ( I made that mistake before. Happens when you use a
code generator too easily...)
Concerning point 2 (Using a primary key for a struct key) for the
sake of simplicity I made the collection types arrays.
But then still remains the issue:
I get 2 arrays: Contact.getRepr1Array() and Contact.getRepr2Array().
When IDContact links to IDPerson one array contains Representative
objects, the other being empty,
but when IDContact links to IDOrganization I get 2 identical arrays.
Setting lazy="true" for both onetomanys (repr1 and repr2) returns 2
arrays, always one being empty, which to me makes sense.
Setting lazy is not a problem, I was just wondering why the above
behaviour was happening.
- Richard
On Oct 9, 10:47 pm, "Mark Mandel" <[EMAIL PROTECTED]> wrote:
> Since you haven't provided your Transfer version, or what DB you are
> on, or your table structure, I can only
> guess:http://groups.google.com/group/transfer-dev/web/how-to-ask-support-qu...
>
> 1) You can only use Foriegn keys for properties or for relationships, not
> both.
> 2) Using a primary key for a struct key can cause issues when
> attempting to add new objects to it, thus giving you bad cached data.
> (and gives you no benefit as well, as you can always retrieve from
> Transfer by ID).
>
> Mark
>
>
>
> On Thu, Oct 9, 2008 at 11:30 PM, acdhirr <[EMAIL PROTECTED]> wrote:
>
> > Looks like setting lazy="true" for both onetomany's solves the
> > identical struct problem. One always being empty, I can safely merge
> > them into one struct so I don't have to decide which one to choose.
>
> > Still puzzles me why this is happening...
>
> > On Oct 9, 1:26 pm, acdhirr <[EMAIL PROTECTED]> wrote:
> >> Dear folks at the transfer list,
>
> >> Please help me with a tough issue.
>
> >> I have a table structure as below (simplified transfer xml)
>
> >> Contacts basically stores addresses of both persons and
> >> organizations.
> >> Each organization can be linked to several persons, whereas each
> >> person can be linked to
> >> several organizations.
>
> >> A linking table is required, but it's not just a linking table, it
> >> also stores information
> >> describing the type of relationship between a person and an
> >> organization and a number of other fields.
> >> Therefore I can't use a manytomany.
>
> >> The linking table links Contacts to Contacts.
>
> >> This is my (simplified) transfer:
>
> >> <object name="Contacts" table="contacts">
>
> >> <id name="IDContact" column="code" type="string" />
> >> ...
>
> >> <onetomany name="repr1">
> >> <link to="Representatives" column="IDPerson" />
> >> <collection type="struct">
> >> <key property="IDRepresentative" />
> >> </collection>
> >> </onetomany>
>
> >> <onetomany name="repr2">
> >> <link to="Representatives" column="IDOrganization" />
> >> <collection type="struct">
> >> <key property="IDRepresentative" />
> >> </collection>
> >> </onetomany>
>
> >> </object>
>
> >> <object name="Representatives" table="representatives">
>
> >> <id name="IDRepresentative" />
> >> <property name="IDPerson" />
> >> <property name="IDOrganization" />
> >> <property name="job" />
> >> ...
>
> >> </object>
>
> >> Since manytomany is not an option, I took two onetomany's. That's
> >> going to return me 2 structs:
>
> >> Contact.getRepr1Struct() and Contact.getRepr1Struct().
>
> >> Strangely, when IDContact links to IDPerson I get only one struct
> >> containing Representative objects, but
> >> when IDContact links to IDOrganization I get 2 identical structs.
>
> >> Now I can live with that, with some conditional logic I could test to
> >> see if at least one struct
> >> is loaded and then take that struct.
>
> >> But it just strikes me as odd, which could suggest that I am
> >> completely going the wrong direction.
>
> >> So I was wondering if anyone has an explanation for this behaviour, or
> >> maybe another approach for these
> >> self referencing many-to-many's.
>
> >> Thanks,
> >> Richard
>
> --
> E: [EMAIL PROTECTED]
> W:www.compoundtheory.com
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---