shafiq.rst khan Wed Sep 25 07:39:01 -0400 2013

Subject: has_many with sub query conditions

Hi

What i need in has many is subquery like

static $has_many = array(
array('userpost', array('conditions' => array('user_id in (SELECT friend_id FROM userfriends WHERE user_id = $this->id) AND id != $this->id'),
);

But is showing me error (syntax error)
can any one help me to figure it out what is issue with this


Bill Zhao Mon Sep 30 03:27:41 -0400 2013

#error static vs $this 

#so... use function instead associations
public function userposts()
{
    return static::all(
        array(
            'conditions' => array("`user_id` in (SELECT friend_id FROM userfriends WHERE user_id = {$this->id}) AND id != {$this->id}')
        )
    );
}

shafiq.rst khan Mon Sep 30 03:42:28 -0400 2013

Thanks Bill Zhao,

I know this process. and currently using same But what i am looking is same functionality like ruby and rail finder_sql

(1-2/2)