I have the following tables
Role
(id int…
,name …
);
User
(id
,name
,role_id (foreign key to Role.id)
)
Partner
(id
,acct_mgr (foreign key to user.id)
)
I defined scopes for Role
public function scopes()
{
return array(
'acctmgr'=>array('condition'=>"role='Account Manager'",),
);
}
I defined scopes for User
public function scopes()
{
return array(
'acctmgrs'=>array( 'condition'=>"role.role='Account Manager'", 'with' => 'role', ), /* works */
/* does not work --> ‘acctmgrs’=>array( ‘condition’=>“role_id=”.Role::model()->acctmgr()->find(), ), */
);
}
In the _form (create page for the Partner model) I have the following:
<div class="row">
<?php echo $form->labelEx($model,'acct_mgr_id'); ?>
<?php echo $form->dropDownList($model, 'acctMgr', CHtml::listData(User::model()->acctmgrs()->findAll(),'id', 'username'), array('prompt' => 'Select Account Manager')); ?>
<?php echo $form->error($model,'acct_mgr_id'); ?>
</div>
But it blows up
Should I be able to define the scope as
‘acctmgrs’=>array( ‘condition’=>“role_id=”.Role::model()->acctmgr()->find(), ),
Get the set of Account Manager Roles (could be one or more) and then get the set of Users who belong to that role.
I am missing something very basic and confused.
Thanks for any help.