0

I know this is an old quastion, but I just can't seem to make It work.

I have these relationships:
User hasMany Responsible
Responsible belongsTo User

I need, through my User model, perform a find like this:

$users = $this->User->find('all', array('conditions' => array('Responsible.email' => $responsible_email));

But this won't work, It will throw a "Unknown column 'Responsible.email' in where clouse".

my real code is like this:

    $conditions = array();

    if (!empty($params['filter_by_name'])) {
        $conditions[] .= "LOWER(CONCAT(Profile.name, ' ', Profile.surname)) LIKE '%".$params['filter_by_name']."%'";
    }

    if (!empty($params['filter_by_email'])) {
        $conditions[] .= "LOWER(User.email) = '".$params['filter_by_email']."'";
    }

    if (!empty($params['filter_by_responsible_email'])) {
        $conditions[] .= "LOWER(Responsible.email) = '".$params['filter_by_responsible_email']."'";
    }

    $results = $this->User->find('all', array('conditions' => $conditions));

I have searched and tried in many ways, but I just can't make It work, how do I do this?

Edit:

I was able to do It with containable, but it also returns User with empty Responsible...

4

1 に答える 1

1

とった:

       $options['joins'] = array(
            array(
                'table' => 'responsibles',
                'alias' => 'Responsible',
                'type' => 'INNER',
                'conditions' => array("User.id = Responsible.user_id")
            )
        );

        $conditions[] .= "Responsible.email = '".$params['filter_by_responsible_email']."'";

        $options['conditions'] = $conditions;

        $results = $this->User->find('all', $options);

うまくいきます:)

于 2012-08-13T00:36:31.227 に答える