Yii Framework Forum: Model Self Relation Search - Yii Framework Forum

Jump to content

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

Model Self Relation Search Search Empty :( Rate Topic: -----

#1 User is offline   Yamilquery 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-January 14
  • Location:México, Querétao

Posted 17 January 2014 - 11:40 AM

Controller:
    $criteria=new CDbCriteria;
    $criteria->compare('miembro.nombre','Ricardo',true);
    $criteria->with=array(
            'miembro'
        );
    $criteria->together = true;
    $m = Miembro::model()->findAll($criteria);


$m return Array Empty :(

Model Miembro.php:
public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'miembro' => array(self::HAS_ONE, 'Miembro', 'id_escuela'),
		);
	}


I hope someone can help me...

Thx! :)
0

#2 User is offline   Dave 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 187
  • Joined: 09-October 08

Posted 17 January 2014 - 11:49 AM

Did you check to sql query log to see what actual query is generated by the criteria?
0

#3 User is offline   Yamilquery 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-January 14
  • Location:México, Querétao

Posted 17 January 2014 - 12:10 PM

You was right!

I changed my code by:

Controller:
$criteria=new CDbCriteria;
    $criteria->compare('miembro.nombre','Lorena',true);
    $criteria->with=array(
            'escuela',
            'miembro'=>array('alias'=>'t2','join'=>'LEFT JOIN `miembro` `miembro` ON (`miembro`.`id_escuela`=`t`.`id_escuela`) ')
        );
    $criteria->together = true;
    $m = Miembro::model()->findAll($criteria);


Thanks so much! :D
0

#4 User is offline   uEhlO4a 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 05-January 14
  • Location:Ukraine, Kiyv

Posted 17 January 2014 - 02:29 PM

maybe HAS_ONE --> BELONGS_TO ?
0

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