Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SS 2.4 can't fetch data with 'get_one' where filter -> unknown column

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 587 Views
  • BlackHawk
    Avatar
    Community Member
    7 Posts

    SS 2.4 can't fetch data with 'get_one' where filter -> unknown column Link to this post

    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.

    $id= 7;
    $val = DataObject::get_by_id('Profession', $id);

    Anybody out there who knows what I am doing wrong?

    Thank you for your help!

  • martimiz
    Avatar
    Forum Moderator
    1037 Posts

    Re: SS 2.4 can't fetch data with 'get_one' where filter -> unknown column Link to this post

    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'");

  • BlackHawk
    Avatar
    Community Member
    7 Posts

    Re: SS 2.4 can't fetch data with 'get_one' where filter -> unknown column Link to this post

    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'

  • martimiz
    Avatar
    Forum Moderator
    1037 Posts

    Re: SS 2.4 can't fetch data with 'get_one' where filter -> unknown column Link to this post

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

  • BlackHawk
    Avatar
    Community Member
    7 Posts

    Re: SS 2.4 can't fetch data with 'get_one' where filter -> unknown column Link to this post

    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.

    Greetz.

    587 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.