Whats the usual practice in getting a behavior (linked to multiple models) to build filters for SQL queries, and then read the table that belongs to that model?
I have a Behavior function which is meant to do a database query with certain SQL conditions. I currently pass in the $this->request->data.
I have issues building the SQL conditions because i'm not sure how to derive the name of the table (that corresponds to the model). See below for example, I want to change "BillingCenterDetail" which is the table name (and also the model name), to something generic I can use across different models. I want this table name to be derived automatically based on the model name. I'm not sure if i can use the $model reference for that.
public function saveWithTimeConstraintCheck(Model $model, $data) { //FIND ALL RECORDS THAT OVERLAP $overlapfilter = array( 'BillingCenterDetail.billing_center_id =' => $data['BillingCenterDetail']['billing_center_id'], 'BillingCenterDetail.startdate <=' => $data['BillingCenterDetail']['enddate'], 'BillingCenterDetail.enddate >=' => $data['BillingCenterDetail']['startdate'] ); ... after building the filter, I can use $model->find to execute the query, this should be OK because its generic.
$overlapresults = $model->find('all', array('conditions' => $overlapfilter));