Getting error Error: You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members

654 views
Skip to first unread message

Veronica

unread,
Sep 29, 2016, 9:59:47 AM9/29/16
to CFWheels
I am getting emails with the error:

Error:
You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members. 

At different parts in the application that were working ok.

Not sure what is going on.

Most of these involve findAll or findOneById, etc. The row the email tells me the error is at, has a query.

How can I know more about what is the variable causing the problem??? The email doesn't tell me. Is there a way to get some more information? 

I have added reload=true to the functions and it seems to have corrected the problem, but I cannot be sure since at times it works ok and at times it doesn't. 

Any help will be very appreciated.

Thank you.

Chris Peters

unread,
Sep 29, 2016, 10:09:54 AM9/29/16
to cfwh...@googlegroups.com
I've tended to find that the best strategy with the error emails is to review all of the details about the request and then try to replicate the request as close as possible myself in my dev environment.

Questions I ask:
  • What is the referer of the page?
  • Is anyone logged in? If so, who?
  • What was the user submitting via a form (if any)?
  • What do the database records that they were trying to access look like?
That last question can be the trickiest because you're not guaranteed to know what the database looked like. But I can usually spot the problem 90% of the time if it's related to that.

--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+unsubscribe@googlegroups.com.
To post to this group, send email to cfwh...@googlegroups.com.
Visit this group at https://groups.google.com/group/cfwheels.
For more options, visit https://groups.google.com/d/optout.



--

Chris Peters
Web Developer
Liquifusion Studios

chris....@liquifusion.com
Skype: liquifusion.support
www.liquifusion.com

Tom King

unread,
Sep 29, 2016, 10:10:42 AM9/29/16
to CFWheels
This is almost definitely when you're trying to do a findOne call where the result is false, i.e, not found.

FindOne will try and return an object by default (you can set it to query if you need though)
FindAll will always return a query, even if it's empty.

i.e, 
user=model("user").findOne(where="name='bob'"); // returns an object
#user.name# // will output bob in your view, as name is a "member" of the "user" struct/object

user=model("user").findOne(where="name='idontexist'"); // returns false.
#user.name# // will throw an error, as user actually equals false and isn't a structure with all our data in it. it's just a string (well, boolean).

So the way round it is:
user=model("user").findOne(where="name="idontexist"); // returns false.
if(isObject(user)){
 // carry on
} else {
// do something else, like say "hey not found!"
}

Or if doing multiple records/query:
users=model("user").findAll(where="name='idontexist'"); //  still returns a query even if false.

So you can just do 

if(users.recordcount){
// We've found some users
} else {
// Nothing returned
}

T
Reply all
Reply to author
Forward
0 new messages