Teddy,Right. But that is for one record. I need to do the same thing for all records in the staff table to produce the listing. Hence my confusion. So if I ran the code below, I would need to loop over all records in the staff table. ---------
OK. I think it just clicked. Is this a proper way to do what I want? (Code edits preceded by ******)
ColdFusion Code: <!--- load the reactor factory ---><cfset Reactor = CreateObject("Component", "reactor.reactorFactory").init(expandPath("reactor.xml ")) />
<!--- get all records --->
******<cfset staffGateway = reactor.createGateway("staff") />
******<cfset qryStaff = staffGateway.getAll()>
******<cfoutput query="qryStaff">
<!--- get the staffer record for the staff person with the primary key
on current row of the staff --->
******<cfset staffRecord =
reactor.createRecord("staff").load(staffID=#qryStaff.StaffID#) />
<!--- get the address record for the staffer record loaded---> <cfset staffAddressRecord = staffRecord.getAddress() /><!--- the isDirty method of the staffer's address link will tell you if an address record was found or not for the staffer --->
<cfset badRead = staffAddressRecord.isDirty()> <cfoutput> <!--- display the staffer's name from the staff table' ---> #staffRecord.getStafferName()#<br /><!--- if it was not a bad read of the address table for the staffer, display the address and state --->
<cfif not badRead> <!--- get the address of the staffer from the address table ---> #staffAddressRecord.getAddress_One()#<br /> <!--- get the state of the staffer from the address table ---> #staffAddressRecord.getState()#<br /> </cfif> </cfoutput> Byron Teddy Payne wrote:
Byron,Why would you need a query? You created a one-to-one relationship in your reactor.xml. The sample code that I sent you will give you the Address for a given staffer.The load() method creates the query to join the two tables together when you set the primary key on the staff record. That is time saving of Reactor.TeddyOn 7/25/06, *Byron Raines* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:Teddy, And there in lies my problem, I think. From what I understand, the gateway works on a table. When I use that method, I do not get direct access to the data in the other table that has the "hasOne" relationship. Right now I have to write a separate query that joins the two tables, use createGateway() on that query, then cfoutput as normal. My thought originally when I come across this thread was that if you do a createGateway, then a getAll() and the table has a "hasOne" relationship with other tables, shouldn't you be able to access the related table data without having to write a separate query? If I have to write a separate query, so be it. I was looking for a more efficient way to display a listing of data from 2 related tables. Thanks for you patience on this. Byron Teddy Payne wrote: > Byron, > Displaying all staff records would be a gateway. > > <cfset Reactor = > CreateObject("Component","reactor.reactorFactory").init(expandPath("reactor.xml > ")) /> > <cfset staffGateway = reactor.createGateway("staff") /> > <cfset qryStaff = staffGateway.getAll()> > > qryStaff returns a query object, so you can use cfoutput or cfloop if > you like. > > I recommend reading http://livedocs.reactorframework.com/ > > This is covered in the "Reactor Crash Course" portion of the left > navigation. > > > On 7/24/06, *Byron Raines * <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> >> wrote: > > Thanks, Teddy. That's really helpful. Esp. the info on isDirty > (hadn't > got that far). Now to take this further. To display all staff in the > table, would I need to <cfloop> over all the records? Is this the > most > efficient way? or is there another way? > > Thanks again. > > byron > > Teddy Payne wrote: > > Byron, > > As promised, here is the reactor snippet. The reactor.xml was > located > > in my webroot in a folder called sample. I created a mapping to > > sample/data folder to store the generated reactor objects. > > > > I also included a basic logic to detect if you have found an address > > for a given staffer. > > > > Reactor.xml: > > <reactor> > > <config> > > <project value="sample" /> > > <dsn value="reactor" /> > > <type value="mssql" /> > > <mapping value="/sampleData" /> > > <mode value="development" /> > > </config> > > > > <objects> > > > > <object name="Staff"> > > <hasOne name="Address"> > > <relate from="staffID" to="staffID" /> > > </hasOne> > > </object> > > > > </objects> > > > > </reactor> > > > > ColdFusion Code: > > <!--- load the reactor factory ---> > > <cfset Reactor = CreateObject("Component", > > "reactor.reactorFactory").init(expandPath("reactor.xml ")) /> > > > > <!--- get the staffer record for the staff person with the primary > > key on the staff table of 1 ---> > > <cfset staffRecord = > reactor.createRecord("staff").load(staffID=1) /> > > > > <!--- get the address record for the staffer record loaded---> > > <cfset staffAddressRecord = staffRecord.getAddress() /> > > > > <!--- the isDirty method of the staffer's address link will tell you > > if an address record was found or not for the staffer ---> > > <cfset badRead = staffAddressRecord.isDirty()> > > > > <cfoutput> > > <!--- display the staffer's name from the staff table' ---> > > #staffRecord.getStafferName()#<br /> > > > > <!--- if it was not a bad read of the address table for the staffer, > > display the address and state ---> > > <cfif not badRead> > > <!--- get the address of the staffer from the address table > ---> > > #staffAddressRecord.getAddress_One()#<br /> > > <!--- get the state of the staffer from the address table ---> > > #staffAddressRecord.getState()#<br /> > > </cfif> > > > > </cfoutput> > > > > -- > > <cf_payne /> > > http://cfpayne.wordpress.com/ <http://cfpayne.wordpress.com/> > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- > > -- -- -- -- > > Reactor for ColdFusion Mailing List > > [email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>> > > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ <http://www.mail-archive.com/reactor%40doughughes.net/> > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > > -- -- -- -- > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- -- -- -- > Reactor for ColdFusion Mailing List > [email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>> > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > <http://www.mail-archive.com/reactor%40doughughes.net/ <http://www.mail-archive.com/reactor%40doughughes.net/>> > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- -- -- -- > > > > > -- > <cf_payne /> > http://cfpayne.wordpress.com/ <http://cfpayne.wordpress.com/> > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- -- -- > Reactor for ColdFusion Mailing List > [email protected] <mailto:[email protected]> > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Reactor for ColdFusion Mailing List [email protected] <mailto:[email protected]> Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- <cf_payne /> http://cfpayne.wordpress.com/-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --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/ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
