Jump to content
Larry Ullman's Book Forums

smayzes

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About smayzes

  • Rank
    Newbie
  1. I should note that I beleive I figure this out. Where I do: $criteria->compare( 'instructorToken.first_name', $query, true ); I should have put: $criteria->compare( 'Users.first_name', $query, true ); Users being the model name and not the relation name. Thank you so much for the help!
  2. Hi, thanks for the link, I read through them and I did realize that my Users model did not have the HAS_MANY relationship. I added it like so: public function relations() { return array( 'lessons' => array(self::HAS_MANY, 'Lessons', 'instructor_token'), ); } I still get the error however and in brushing up on related models, I still end up stuck as what I understand from reading is that I should be able to run my criteria comparison using: $criteria->compare( 'instructorToken.first_name', $query, true ); as 'instructorToken' is the relation and as I understand, I should be able to use as the alias it since I am loading that relation with the 'with()' method. 'first_name' is in fact a record in the User model and I should be able to search it. Correct? (I hope) I should mention my query variable is a string that user has entered into a text box. I'm hoping to allow the users to compare the $query to some of the records in the Lessons model and the Users model.
  3. Hi there, I'm a bit stuck on providing a solution for searching records in a CListView. In my code I have: LessonsController.php public function actionIndex() { $model = new Lessons('search'); // Clear any default values $model->unsetAttributes(); $this->render('index',array( 'dataProvider'=>$model->search(), 'model'=>$model )); } Lessons.php public function search() { // Get the typed query string $query = Yii::app()->request->getQuery('query'); $criteria = new CDbCriteria; // Package Name $criteria->compare('package_name', $this->package_name, true); // Quantity Name $criteria->compare('quantity_name', $this->quantity_name, true); // Package Id $criteria->compare('package_id', $this->package_id, true); // Do we have a search query string? if ( !empty($query) ) { $criteria->with = array('instructorToken'); $criteria->compare( 'instructorToken.first_name', $query, true ); $criteria->together = true; } return new CActiveDataProvider(get_class($this), array( 'criteria' => $criteria, )); } As you can see I'm trying to use the with() method to search another table for the first name. I have a relation which is as follows: public function relations() { return array( 'instructorToken' => array(self::BELONGS_TO, 'Users', 'instructor_token'), ); } I get an error that states: Now I'm confused as I do have 'first_name' in the Users model. Also reading the documentation of the with() method says it requires the key from the relations method, which I have. Anyone have any idea what I'm doing wrong or missing?
×
×
  • Create New...