This is a topic that is starting to arise in the other thread about determining the table name from an alias with a Reactor component, so I thought I would break it out into its own thread.

In SQL an "alias" is (I believe) a different thing than an alias in Reactor. In SQL, an alias is something you give to a table to make referencing it *within the query* easier. In Reactor, an alias is something you give to a table or to table columns that lets you or reactor use the alias to determine the mapped table or column name throughout the entire framework. This seems to be proven by looking at the components reactor creates: when you specify an alias for a table, the CFC reactor generates contains the alias name, not the table name. This may be a point of confusion for some people, so if my logic here is correct it might be worthwhile to point this out in the docs.



On 4/13/06, Brian Kotek <[EMAIL PROTECTED]> wrote:
I'll have to do some tests to confirm, but if you give two tables the same alias that would seem to create a problem. If you ask reactor for a gateway and specify an alias that was used more than once in the Reactor XML, how does Reactor know which table you're referring to? I don't see how it could.



On 4/13/06, Bowden, Beth (NIH/NIEHS) [E] < [EMAIL PROTECTED]> wrote:

I gave two different tables the same alias and then created a gateway, record, … etc using that alias w/o a problem. This may be a gotcha if you inadvertently use the same alias twice.

Beth


From: Brian Kotek [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 13, 2006 8:37 AM


To: [email protected]
Subject: Re: [Reactor For CF] Determine table names in custom query?

 

To add one thought, maybe the getTableForAlias() (or whatever it would be called) would be at home in the Reactor Config object rather than the base Reactor object, but regardless of where it lives, I think something like this should be available.

On 4/13/06, Brian Kotek <[EMAIL PROTECTED]> wrote:

Yep, I'm aware of the Query object. But what if your custom query is complex (multiple joins, group by, aggregate or custom SQL functions, etc.)? No matter how we slice it there will certainly be times when you simply have no choice but to write a query out by hand (after all, that is what the custom gateway and DAO components are for). And in those cases, it seems reasonable to want to leverage the configuration information you supplied in the Reactor XML file. After all, I've already told Reactor what aliases map to what tables and it seems like being able to get to that configuration information would be very valuable. I'm saying I think a method like the one I attached earlier should be added to the base Reactor object to make this easy (assuming I'm not missing some existing way to get at this configuration information).

 

On 4/12/06, João Fernandes < [EMAIL PROTECTED]> wrote:


Well I also realized the problem using the alias instead of the table name but if you want to build custom queries with joins you should take a look to the createquery() method. The Query Object have multiple functions that allow you to build all kind of custom queries, including joining tables.

João Fernandes

-----Original Message-----
From: [EMAIL PROTECTED] on behalf of Brian Kotek
Sent: Thu 13-Apr-06 12:49 AM
To: [email protected]
Subject: Re: [Reactor For CF] Determine table names in custom query?

Thanks for the response Joao, but there are two problems with that. First, I
already know the alias and I want the actual table name that is mapped to
the alias. Placing the alias into the SQL statement would result in an error
if the alias is different from the table name (which mine is).

And second, if my query needs to join to a table outside the current object
for some reason, I would want to be able to get the table name for *any*
alias that I give it.

On 4/12/06, João Fernandes < [EMAIL PROTECTED]> wrote:
>
> Your gateway has a private function getObjectMetadata() that will return a
> reactor.base.abstractMetadata object.
>
> That object has several methods like getAlias() ;)
>
> so you could use
>
> <cffunction name="myCustomGatewayMethod">
> select *
> from #getObjectMetadata().getAlias()# where ...
> </cffunction>
>
> Not tested but it should work
>
> João Fernandes
>
>




-- 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