Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

return query from one CFC to another CFC

Guest
May 13, 2008 May 13, 2008
I have a CFC called "order.cfc". Also in this app is a CFC called "user.cfc".

In my order.cfc, one of the functions will setup and create a new order for an existing user. The user ID is passed to the function "createOrder" in order.cfc.

Instead of duplicating a function called "getUser" from user.cfc, I figured I could pass the arguments.userID from order.cfc over to the getUser function of user.cfc and get my query result back:

<cfset thisCustomer = createObject("component","user").getUser(arguments.userID) />

Obviously, I'm doing something wrong as I keep getting this error message:
The value returned from function getUser() is not of type query.

However, getUser does return a proper query data type when I access that component directly and not from this other cfc.

TOPICS
Advanced techniques
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2008 May 13, 2008
It's pretty hard to tell what's going on without seeing your code.

What we need is the CFM template that's initially calling (some method you
don't identify) in order.cfc, the code of [that mystery method], and the
code of the getUser() method from user.cfc.

Then we might have a chance of working out where you're going wrong.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2008 May 13, 2008
Did you try to use cfinvoke instead of cfset?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 16, 2008 May 16, 2008
One possible explaination could be that your getUser() method is generating an error before it can complete and return a query. Double check your values of arguments.userID and your error checking inside getUser() to make sure you are always returning a query and/or alerting yourself when something goes wrong.

Also, I like Dan's idea of the cfinvoke.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 May 16, 2008
>> Did you try to use cfinvoke instead of cfset?
> Also, I like Dan's idea of the cfinvoke.

What is the difference you and Dan perceive in using <cfinvoke> over
createObject() (<cfset> really has nothing to do with it).

Both achieve the same end, but <cfinvoke> is really a very clunky
construct.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 17, 2008 May 17, 2008
quote:

Originally posted by: Newsgroup User

What is the difference you and Dan perceive in using <cfinvoke> over
createObject() (<cfset> really has nothing to do with it).

--
Adam


Since you asked.

This is the line of code:
<cfset thisCustomer = createObject("component","user").getUser(arguments.userID) />

My style is to be a bit more methodical. If I were going to use createobject, I would do it like this:

MyObject = createObject("component","user");
thisCustomer = MyObject.getuser(arguments.userID);

If I wanted to do it in one line, or if I were only going to call one function from that component, I'd use cfinvoke.
I'm simply not clever enough to try using cfset like that. I had no idea it would work.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 May 16, 2008
Adam Cameron wrote:
>
> Both achieve the same end, but <cfinvoke> is really a very clunky
> construct.
>

This maybe taking this down a side path, but there are times where
<cfinvoke...> work and createObject() does not. Primarily when dealing
with a shared hosting provider of course. Since createObject() can do
much more then create CFC instances it is often disabled. But
<cfinvoke...> being restricted to components can be allowed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2008 May 17, 2008
SteveLogan1029,

verify that the function has the following two extra attributes and that its return variable is actually a query.

<cffunction name="getUser" output="No" returntype="query">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2008 May 17, 2008
LATEST
Dan Bracuk wrote:
I'm simply not clever enough to try using cfset like that.

In my opinion, your two-line way is the cleverer.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources