Ok, let me try to address your questions:
Q: Can I join to another table from an Iterator? IE: to get the emailType
from the email Iterator.
A: No. An Iterator represents a collection of one type of object. For
example, the Email Iterator is designed to behave like a collection of
AddressRecords. If you were to join to another object such as emailType I
wouldn't be able to provided this functionality.
Q: How can I get to the emailType from an Email Iterator?
A: You could loop over the collection and get an emailRecord on each loop.
Your emailRecord can easily be configured to haveOne emailType. Thus your
code could look like this:
<cfloop condition="#EmailIterator.hasMore()#">
<cfset EmailRecord = EmailIterator.getNext() />
<cfoutput>
Email: #EmailRecord.getEmailAddress()#<br>
Type: #EmailRecord.getEmailTypeRecord().getDescription()#
</cfoutput>
</cfloop>
Q: But that really runs a query and then runs another query on each loop.
That beaks the cardinal rules I learned when I started coding CF!
A: Yes and no. The question is, what impact will this really have on your
app? Will each EmailRecord have dozens of emailTypes? Will you Person have
dozens of emailAddresses? If so, this is probably not the best option. If
not, it's worth considering.
Ultimately, Reactor is about reducing the amount of tedious, repetitive code
you have to write. Its focus is not necessarily on speed. So, if this is
too slow for you then you should write your own method that runs your own
query. That's why I added the customizable CFCs for you. If your query
uses functionality that's DBMS-specific then it should do in the
DBMS-specific customizable file.
I hope that helps,
Doug
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cody
Caughlan
Sent: Tuesday, February 28, 2006 8:10 PM
To: [email protected]
Subject: [Reactor For CF] Linking objects and types
I have the following tables: Email, Person, Email_Types (e.g. Home, Office,
etc). Person and Email are linked using the standard link table. There is a
"TypeID" in the Email table which refers to the Email_Types table. Its
possible for me to do this:
<cfset EmailAddressQuery = PersonRecord.getEmailIterator.getQuery()>
And this represents a query of all the email addresses for the given Person
that I have previously load()ed. Now if I dump out the that query it only
contains the fields that are in the actual Email table, as expected. How
would I set it up so that the email query would join itself on the "TypeID"
field and bring in that info? Would I have to loop over my query and do a
Reactor.createRecord("Email") and muck with the Query object to do a join on
"Email_Types" is there some way I can have all of this done for me
(preferably w/o incurring the overheard of looping over the query and
creating each EmailRecord when having just a query for display purposes
would suffice)?
I have something like this in my reactor.xml
<object name="Email">
<hasOne name="Email_Types" alias="EmailType">
<relate from="TypeID" to="ID" />
</hasOne>
</object>
But when I am talking to my EmailIterator via my PersonRecord it doesnt
really know about it:
<object name="Person">
<hasMany name="Email">
<link name="PersonEmailLink" />
</hasMany>
</object>
So I am not sure how to bring it all together. How about if in the future I
wanted to take a step back and operate on Emails w/o going thru
PersonRecord?
Thanks
/Cody
-- 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/