Populate Checkbox List

Suppose I have the following:

Listing model:


public $selections;


// model relation - listing can have many categories 

'listing_cats'=>array(self::HAS_MANY, 'ListingCategory', 'listing_id'),

ListingCategory table has fields: id, listing_id, category_id

Listing View:


<?php echo $form->checkBoxList($model, 'selections', Category::model()->getCategoriesList()); ?>

Category model:


public function getCategoriesList()

{

	return CHtml::listData($this->findAll(), 'id', 'name');

}

How can I reference the ‘listing_cats’ relation to populate the checkboxlist, i.e pre-tick the selections that exist for this record?

I wouldn’t use the active checkBoxList, put just the standard one





$selected_ids=array(2,5,23);


echo CHtml::checkBoxList('field_name[]', $selected_ids, Category::model()->getCategoriesList());




Categories 2, 5 and 23 will be selected.

What’s the best way of retrieving just the IDs of records from a has many relation to populate a checboxlist?