0

I have three relationships in my database, actions, action types and social media. Every action has an action type and the same action type can be shared by many actions. Also, every action belongs to a specific social media which can be shared by many actions too. So within this context, "Action" is a join model between social media and action types.

I'm beginning with CakePHP and what I need is to generate a list with action types in the format social network - action type name. I've already set up the Action, ActionType and SocialMedia model associations in my app, but trying to execute

$actionTypes = Set::combine($this->Action->ActionType->find('all', array(
        'fields' => array('ActionType.id',"CONCAT(SocialMedia.name,' ',ActionType.name) as name"),
        'contain' => array('SocialMedia')
    )),'{n}.ActionType.id','{n}.0.name');

Throws a SQL error saying that there's no such column SocialMedia.name

tereško
  • 58,060
  • 25
  • 98
  • 150
danielperaza
  • 412
  • 3
  • 12

1 Answers1

0

Containable will create separate query for each table and combine it afterwards. In your case, CakePHP will create one query for ActionType table and another separate query for SocialMedia.

Read this tutorial from Mark Story for more details http://mark-story.com/posts/view/using-bindmodel-to-get-to-deep-relations

You can use bindModel as he mention in the tutorial to perform one query and make the SocialMedia.name column available.

Rudy Lee
  • 438
  • 5
  • 18