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

return query from one CFC to another CFC

Guest
May 13, 2008 May 13, 2008

Copy link to clipboard

Copied

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

Views

1.2K

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Did you try to use cfinvoke instead of cfset?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Documentation