Is this related to the thread that I posted a few weeks ago, titled "Mapping
Question". In that thread, I had a problem with 1-to-1 mappings. Sean
Corfield posted a fix to the project.dao.xsl file and this worked for me. I
am not sure if this fix was committed to SVN or not. 

Search the archives for "Mapping Question" and the XSL fix is in there or
maybe Doug can tell us whether or not he committed it. If he did then my bad
and your problem is unrelated.

/Cody 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Doug Hughes
Sent: Saturday, March 18, 2006 2:43 PM
To: [email protected]
Subject: RE: [Reactor For CF] Support for one-to-one relations?

Dave - 

Let's say you have a User who hasOne address. That is, the address has a
field userId which is a foreign key back to the User's userId field.  

To configure this correctly you would add an object to your reactor xml that
looks like this:

<object name="User">
        <hasOne name="Address">
                <relate from="userId" to="userId" />
        </hasOne>
</object>

Or, perhaps, that your User actually has an addressId field that is foreign
key to your Address' addressId field.in that case your config would look
like this:

<object name="User">
        <hasOne name="Address">
                <relate from="addressId" to="addressId" />
        </hasOne>
</object>

In both cases this will cause reactor to generate a method
getAddressRecord() on your UserRecord.  The getAddressRecord() method
returns an AddressRecord.

If you wanted to get really crazy you could make a reference back to the
user from the address by adding another hasOne relationship back:

<object name="Address">
        <hasOne name="User">
                <relate from="addressId" to="addressId" />
        </hasOne>
</object>

Or...


<object name="Address">
        <hasOne name="User">
                <relate from="userId" to="userId" />
        </hasOne>
</object>

... depending on your database configuration.

Hope that helps.

Doug Hughes

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of David A. Cheslow PhD
Sent: Saturday, March 18, 2006 1:39 PM
To: [email protected]
Subject: Re: [Reactor For CF] Support for one-to-one relations?

Thanks for responding Brian.  I finally got a chance to download the latest
version and checkout your suggestions.  I'm afraid I still only see support
for one-to-many and many-to-many relations.

The samples show Customer and Address in a one-to-many relation rather than
a one-to-one relation.  Easy enough to get the Address for a Customer.  A
bit harder to get a Customer for a given Address.

Imagine that the Customer-Address really is a one-to-one relation.   
The way I am doing it now (which is not at all terrible) is to setup a
one-to-many (just like the sample) and then add a getRecord() function to
Address which calls getIterator() and then gets the first and only Customer
from the Iterator.  As I said, it's not terrible...  
just a lot of unnecessary CPU cycles spent.

Am I missing something?

=dave=



On Mar 14, 2006, at 5:48 AM, Brian Hegeman wrote:

> There is definitely support for one-to-one relationships. Check Doug's 
> excellent documentation included in the download -- page 46 has some 
> examples of using <hasOne...> connections. Basically it works just 
> like you've suggested but check the samples.
>
> brian
>
> David A. Cheslow PhD wrote:
>> Hi again;
>>
>> Still loving reactor Doug!  Keep up the great work!
>>
>> Support for Many-to-Many and One-to-Many relations seems pretty 
>> complete... noticeably missing is support for One-to-One relations.
>>
>> Only one of the tables involved in a one-to-one relation needs to  
>> contain a foreign key to the other table.   Relational algebra  
>> does not help us choose which table gets the extra field, but domain 
>> knowledge usually makes it obvious.  Adding a "back pointer foreign 
>> key" from the other table creates ugly problems with cascades and 
>> creates a lot of unnecessary work.  Knowing that the relation is 
>> one-to-one allows the "back reference" to be calculated... just as it 
>> is for the "many" side of a one-to-many relation.
>>
>> Let's say that 'Person' as a one-to-one relation with 'Address'.   
>> We store a foreign key to the Address table in the Person table (we 
>> could just as easily store a foreign key to Person in Address... but 
>> that makes less sense, for some reason).  Reactor allows us to call 
>> getAddressRecord() on a PersonRecord... but it does not allow us to 
>> call getPersonRecord() on an AddressRecord, even though all the 
>> needed information is available.
>>
>> Syntactically, this could be supported the same way that it is for 
>> Many-to-Many relationships.  For example, something like:
>>
>>         <object name="person">
>>             <hasOne name="address" alias="homeaddress">
>>                 <relate from="homeaddressId" to="addressId" />
>>             </hasOne>
>>         </object>
>>
>>         <object name="address">
>>             <hasOne name="person" alias="whereILive">
>>                 <link name="person"  from="addressid"   
>> to="homeaddressid" />
>>             </hasOne>
>>         </object>
>> There are two patterns in which I frequently use one-to-one
>> relations: when a sub-element repeats in an object (e.g. person 
>> has-one 'homeaddress' AND person has-one 'workaddress') and for 
>> storing object hierarchies in a RDB (each instance has a one-to- one 
>> relation with an instance of it's superclass).
>>
>> Adding this functionality outside of reactor is trivial, but it would 
>> also be trivial to add it into reactor...
>>
>> Just food for thought, love the reactor,
>>
>> =dave=
>>
>>
>>
>> -- Reactor for ColdFusion Mailing List -- [email protected]
>> -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/
>>
>>
>>
>
>
> -- Reactor for ColdFusion Mailing List -- [email protected]
> -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/
>
>
>
>


 

-- Reactor for ColdFusion Mailing List -- [email protected]
-- Archives at http://www.mail-archive.com/reactor%40doughughes.net/



 

-- Reactor for ColdFusion Mailing List -- [email protected]
-- Archives at http://www.mail-archive.com/reactor%40doughughes.net/





 

-- Reactor for ColdFusion Mailing List -- [email protected]
-- Archives at http://www.mail-archive.com/reactor%40doughughes.net/


Reply via email to