3063 Posts in 864 Topics by 646 members
|Go to End|
31 August 2012 at 3:07am
Hi @ all,
I am wondering why I can not fetch data from the database with using DataObject::get_one.
I am trying something like this:
$code = 'BE_0007';
$val = DataObject::get_one('Profession', 'Profession_ID = "'.$code.'"');
I get this Error:
Couldn't run query: SELECT "Profession"."ClassName", "Profession"."Created", "Profession"."LastEdited", "Profession"."Profession_ID", "Profession"."Title", "Profession"."Description", "Profession"."ID", CASE WHEN "Profession"."ClassName" IS NOT NULL THEN "Profession"."ClassName" ELSE 'Profession' END AS "RecordClassName" FROM "Profession" WHERE (Profession_ID = "BE_0007") LIMIT 1 Unknown column 'BE_0007' in 'where clause'
When I am trying to fetch the data with DataObject::get_by_id, I don't have a problem to get it.
$val = DataObject::get_by_id('Profession', $id);
Anybody out there who knows what I am doing wrong?
Thank you for your help!
1 September 2012 at 11:14pm
The error probably results from the use of double quotes: Profession_ID = "BE_0007" marks BE_0007 as the name of a column. Try using single quotes, as in:
$val = DataObject::get_one('Profession', "Profession_ID = '$code'");
4 September 2012 at 3:56am
Mmmh, thanks for your help. Unfortunately it did not help.
When I am doing this, I am getting the next error:
[User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'Profession'
4 September 2012 at 4:14am
Ok, but that doesn't necessarily mean the DataObject::get function is not working. First of all - shouldn't you be filtering on ID instead of on Profession_ID? I'm finding it a bit strange the Profession object itself should have a Profession_ID field...
But anyway - based on just this snippet of the error and no further code it's hard to say what's going on...
4 September 2012 at 4:25am
Hey thank's for your reply.
The reason why I have a column 'Profession_ID' is, I need to have this ID humanreadable.
Right now I was able to fix it. With your help and the hint with the quotes.
|Go to Top|