0
I have the following code:
$contacts = $this->Contact->find('all', array(
'limit' => 20,
'contain' => array('Address', 'Phone' => array('fields' => 'Phone.phone' ), 'Campaign'),
'conditions' => array('Contact.campaign_id is not null', $conditions_leads),
'order' => array('Contact.created' => 'DESC')
));
It brings me the following array:
array(
(int) 0 => array(
'Contact' => array(
'id' => '24136',
'source_contacts_id' => null,
'user_id' => '1',
'campaign_id' => '62',
'name' => 'teste PECCIN',
'document' => null,
'email' => '[email protected]',
'gender' => null,
'birthday_date' => null,
'observation' => null,
'contacted' => '0',
'scheduled' => '0',
'invalid_reg' => '0',
'is_active' => '1',
'import_id' => '19',
'dropout_date' => null,
'interested_course' => 'DIREITO',
'parents' => null,
'lead_contacted_date' => null,
'created' => '2014-12-04 16:52:51',
'modified' => '2014-12-04 16:52:51'
),
'Campaign' => array(
'id' => '62',
'name' => 'LEADS - Colégio Estadual Julio De Castilhos',
'enrollment_type' => '1',
'campaign_type' => '1',
'campaign_degree' => '1',
'close_campaign' => '0',
'campaign_entity' => '2',
'import_key' => null,
'created' => '2014-12-04 16:16:33',
'modified' => '2014-12-04 16:16:33'
),
'Address' => array(),
'Phone' => array(
(int) 0 => array(
'phone' => '51111111',
'contact_id' => '24136'
)
)
)
)
I have a condition that checks if the e-mail or phones are already registered in the system:
$conditions_leads['OR'] = array(
'Contact.email =' => $searchEmail,
'Phone.phone =' => $searchTelefone1,
'Phone.phone =' => $searchTelefone2,
);
With email works, more when I put the Phone.phone gives the following error:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Phone.phone' in 'where clause'
Query of SQL:
SELECT
`Contact`.`id`, `Contact`.`source_contacts_id`, `Contact`.`user_id`,
`Contact`.`campaign_id`, `Contact`.`name`, `Contact`.`document`,
`Contact`.`email`, `Contact`.`gender`, `Contact`.`birthday_date`,
`Contact`.`observation`, `Contact`.`contacted`, `Contact`.`scheduled`,
`Contact`.`invalid_reg`, `Contact`.`is_active`, `Contact`.`import_id`,
`Contact`.`dropout_date`, `Contact`.`interested_course`,
`Contact`.`parents`, `Contact`.`lead_contacted_date`, `Contact`.`created`,
`Contact`.`modified`, `Campaign`.`id`, `Campaign`.`name`, `Campaign`.`enrollment_type`,
`Campaign`.`campaign_type`, `Campaign`.`campaign_degree`, `Campaign`.`close_campaign`,
`Campaign`.`campaign_entity`, `Campaign`.`import_key`, `Campaign`.`created`,
`Campaign`.`modified`
FROM
`ipa`.`contacts` AS `Contact`
LEFT JOIN
`ipa`.`campaigns` AS `Campaign` ON (`Contact`.`campaign_id` = `Campaign`.`id`)
WHERE
`Contact`.`campaign_id` is not null AND (
(`Contact`.`email` = '[email protected]') OR (`Phone`.`phone` IS NULL)
)
ORDER BY `Contact`.`created` DESC LIMIT 20
Would anyone there tell me why you made a mistake or should I do it another way?
How do I quote him on the FROM line?
– Devidy Oliviera
Do something like:
FROM 'Phone' <resto> WHERE 'Phone'.'phone'
.– mutlei