Why can't Doctrine retrieve my model data?
- by scottm
So, I'm trying to use Doctrine to retrieve some data. I have some basic code like this:
$conn = Doctrine_Manager::connection(CONNECTION_STRING);
$site = Doctrine_Core::getTable('Site')->find('00024');
echo $site->SiteName;
However, this keeps throwing a SQL error that 'column siteid does not exist'. When I look at the exception the SQL query is this (you can see the error is that the inner_tbl alias for siteid is set to s__siteid, so querying inner_tabl.siteid is what's broken):
SELECT TOP 1
[inner_tbl].[siteid] AS [s__siteid]
FROM
(SELECT TOP 1
[s].[siteid] AS [s__siteid],
[s].[name] AS [s__name],
[s].[address] AS [s__address],
[s].[city] AS [s__city],
[s].[zip] AS [s__zip],
[s].[state] AS [s__state],
[s].[region] AS [s__region],
[s].[callprocessor] AS [s__callprocessor],
[s].[active] AS [s__active], [s].[dateadded] AS [s__dateadded]
FROM [Sites] [s]
WHERE ([s].[siteid] = '00024')
) AS [inner_tbl]
Why is the query being generated this way? Could it be the way the Yaml schema is laid out?
Site:
connection: 0
tableName: Sites
columns:
siteid:
type: string(5)
fixed: true
unsigned: false
primary: true
autoincrement: false
name:
type: string(300)
fixed: false
unsigned: false
notnull: true
primary: false
autoincrement: false
address:
type: string(100)
fixed: false
unsigned: false
notnull: false
primary: false
autoincrement: false
city:
type: string(100)
fixed: false
unsigned: false
notnull: false
primary: false
autoincrement: false
zip:
type: string(5)
fixed: false
unsigned: false
notnull: false
primary: false
autoincrement: false
state:
type: string(2)
fixed: true
unsigned: false
notnull: true
primary: false
autoincrement: false
region:
type: integer(4)
fixed: false
unsigned: false
notnull: true
default: (5)
primary: false
autoincrement: false
callprocessor:
type: integer(4)
fixed: false
unsigned: false
notnull: true
primary: false
autoincrement: false
active:
type: integer(1)
fixed: false
unsigned: false
notnull: true
primary: false
autoincrement: false
dateadded:
type: timestamp(16)
fixed: false
unsigned: false
notnull: true
default: (getdate())
primary: false
autoincrement: false