I have two tables, namely 'Customer' and 'Event'. The relations between these two are as follows:
Event
var $belongsTo = array(
...
'Customer'=>array(
'className' => 'Customer',
'foreignKey' => 'customer_id'
)
);
Customer
var $hasMany = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => 'customer_id',
'dependent' => false,
)
);
Each and every customer record holds a company id as well as currently logged in user. What I would like to achieve is to get all of the events for a day, related only to a particular company, but that is of course not working since the event table does not hold company id. Maybe the following find call will help to understand the issue better:
$conditions = array('company_id'=>CakeSession::read("Auth.User.company_id"), 'date'=>date("Y-m-d", $tomorrow));
$tomorrowsEvents = $this->find('all', array(
'conditions'=>$conditions, 'contain'=>array('User', 'Customer')));
Moreover, a customer belongs to a company and a company has many customers, just as follows:
Customer
var $belongsTo = array(
'Company' => array(
'className' => 'Company',
'foreignKey' => 'company_id',
'dependent' => false,
),
);
Company
var $hasMany = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'company_id',
'dependent' => false
),
'Customer'=>array(
'className' => 'Customer',
'foreignKey' => 'company_id',
'dependent' => false
)
);
Any help is much appreciated.