21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 227 Views |
-
Question on DataObject::get

8 October 2011 at 4:50am
The other day I posted a posted a question where I could get objects that had a particular ID
jobsob = DataObject::get('Jobs', 'FamiliesID = 226');
But I wanted to replace 226 with the ID of the class I'm in. I was given this as the solution:
$jobsob = DataObject::get('Jobs', "FamiliesID = {$this->ID}"); And it worked perfectly. I'm just trying to modify it slightly and I get errors.
What I want now.
$jobsob = DataObject::get('Jobs', "FamilyTitle = {$this->Title}"); FamilyTitle is just a different field in Jobs and I want to get the all the Jobs where FamilyTitle is equal to the Title of the object I'm in.
I'd appreciate any idea why this isn't working.
Brian -
Re: Question on DataObject::get

8 October 2011 at 6:48am
This is because the database assumes any non-quoted string is a column name. What you want is "FamilyTitle = '{$this->Title}'". You must use single quotes as the SQL is run in ANSI mode, which means the database treats double quotes as wrappers for column/table names.
If $this->Title could ever contain a single quote itself, you'll want something more like: "FamilyTitle = '" . Convert::raw2sql($this->Title) . "'"
| 227 Views | ||
|
Page:
1
|
Go to Top |

