CakeDC/comments

How can fetch Avatar belongsTo User

Closed this issue · 1 comments

Reported by dien | July 5th, 2011 @ 10:52 AM

How can fetch Avatar belongsTo User, then use behavior containable on Avatar table ?

skie commented

In model possible overload behavior commentBeforeFind method like this

/**

  • Prepare models association to before fetch data
    *

  • @param array $options

  • @return boolean

  • @access public
    */
    public function commentBeforeFind($options) {
    $result = $this->Behaviors->dispatchMethod($this, 'commentBeforeFind', array($options));

      $userModel = $this->Behaviors->Commentable->settings[$this->alias]['userModelAlias'];
      $this->Comment->bindModel(array('belongsTo' => array(
          'Profile' => array(
              'className' => 'Profile',
              'foreignKey' => false,
              'conditions' => array('Profile.user_id = ' . $userModel . '.id')
          )
      )), false);
      return $result;
    

    }