Yii Framework Forum: orber by ambiguous column name - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

orber by ambiguous column name Rate Topic: -----

#1 User is offline   riccardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 02-March 10

Posted 16 March 2010 - 10:54 AM

Hi,

i have two models with a BELONGS_TO relation.

both have a name column.

now if i do something like this:

$activities_c=new CDbCriteria;
$activities_c->with=array(
'macroarea_er',
);
$activities_c->order='name ASC';

it gives me an error saying that name column is ambiguous.

This is correct..the question is..how can i specify which name column it has to use?

Thansk,
Riccardo
0

#2 User is offline   Matt Kelliher 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 12-February 10
  • Location:Tampa, FL

Posted 16 March 2010 - 11:13 AM

Add the table name before the column name, e.g.
$activities_c=new CDbCriteria;
$activities_c->with=array(
  'macroarea_er',
);
$activities_c->order='macroarea_er.name ASC';

0

#3 User is offline   riccardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 02-March 10

Posted 16 March 2010 - 11:33 AM

The other table is called activities, but if i do like this:

$activities_c->order='activities.name ASC';

it gives me this error:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'activity.name' in 'order clause'

while if i do like you suggest:

$activities_c->order='macroarea_er.name ASC';

it works but i nedd the first one to work...

Riccardo

View PostMatt Kelliher, on 16 March 2010 - 11:13 AM, said:

Add the table name before the column name, e.g.
$activities_c=new CDbCriteria;
$activities_c->with=array(
  'macroarea_er',
);
$activities_c->order='macroarea_er.name ASC';


0

#4 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 16 March 2010 - 11:45 AM

use t.name for the main table
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#5 User is offline   riccardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 02-March 10

Posted 17 March 2010 - 03:02 AM

Ok, now it works.
But there is a "rule" to know which t to use?
Because in the query yii use t ,t0 ,t1 and so one..correct?

View Postjayrulez, on 16 March 2010 - 11:45 AM, said:

use t.name for the main table

1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users