0

Currently using Yii framework. I am trying to select a columns in one table and make it an array of a different model. I think yii has a method of doing this, and was wondering what it was. My tables are shown blow:

tables

ticket

ID | code

picks

ID | ticket_ID | Points

I have a list of picks. And I would like to make it into a list of tickets. Any help would be nice. thank you

public static function get_tickets_pick($Points){ $picks = Picks::model()->findAllByAttributes(array('Points'=>$Points)); $tickets = //yii command to convert it return $tickets; } 

1 Answer 1

1

you need to use the function relation. In the Picks Model:

public function relations() { return array( 'ticket' => array(self::BELONGS_TO, 'Tickets', 'ticket_ID'), ); } 

Tickets Model

public function relations() { return array( 'picks' => array(self::HAS_MANY, 'Picks', 'ticket_ID'), ); } 

Then, magically:

public static function get_tickets_pick($Points){ $picks = Picks::model()->findAllByAttributes(array('Points'=>$Points)); foreach($picks as $pick){ $tickets[] = $pick->ticket; } return $tickets; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.