Hi Adam, I am running 1.2 ...
I tried using bind(), but that seems to not work. The array I am getting returned contains no Customer records, which is weird. On Jan 7, 9:17 am, Adam Royle <[EMAIL PROTECTED]> wrote: > You didn't mention what version you are running, but if you using > latest 1.2 code you can use: > > http://bakery.cakephp.org/articles/view/bindable-behavior-control-you... > > If you using earlier version the just use unbindModel and bindModel > customising fields, etc, before you do your query. Also you might run > into probs with bindings being reset when using paginate by default. > > If you're still not convinced then just write a small sql query and > call it like: > > $data = $this->Customer->query($sql); > > Adam > > On Jan 7, 11:27 pm, Travis <[EMAIL PROTECTED]> wrote: > > > bump :) > > > On Jan 6, 10:31 pm, Travis <[EMAIL PROTECTED]> wrote: > > > > Hey everyone, > > > > I'm trying to generate a list of employees and in that list I want to > > > show the customer which that employee belongs to. In my db I have an > > > employees table and a customers table and each employee has a > > > customer_id field. The problem is, I want to show the customer.name > > > field, not the customer_id. > > > > How do I run a select statement that joins these two tables on the > > > customer_id and retrieves only the customer_name from the customers > > > table. > > > > I need to do this from inside the employees controller. Here's my > > > models and controller code. > > > > class EmployeeModel extends AppModel > > > { > > > var $name = "Employee"; > > > var $belongsTo = "Customer"; > > > var $recursive = 1; > > > > } > > > > class Customer extends AppModel > > > { > > > > var $name = "Customer"; > > > var $primaryKey = 'id'; > > > var $hasMany = array('Employee','Transaction'); > > > var $recursive = 2; > > > > } > > > > class EmployeesController extends AppController > > > { > > > > var $name = "employees"; > > > var $helpers = array('DatePicker'); > > > var $uses =array('Employee','Customer'); > > > var $paginate = array( > > > 'limit' => 25, > > > 'order' => array('Employee.id' => 'DESC') > > > ); > > > /* > > > * > > > * > > > * > > > */ > > > function index(){ > > > > //retrieve all of the customers for drop down box and set > > > the data > > > $customerList = > > > $this->Customer->findAll(NULL,array('id','name')); > > > foreach ($customerList as $customer) > > > $customers[$customer['Customer']['id']] = > > > $customer['Customer'] > > > ['name']; > > > $this->set('customers', $customers); > > > > //if data is posted, retrieve all employees specific to > > > the customer > > > id > > > if(!empty($this->data)){ > > > > $this->layout = 'default'; > > > $dataSet = > > > $this->paginate('Employee',array('customer_id' => > > > $this->data['Employee']['customer_id'])); > > > > $this->set(compact('dataSet')); > > > } > > > > //if no data is posted, retrieve all employees > > > else{ > > > $this->layout = 'default'; > > > $dataSet = $this->paginate('Employee'); > > > $this->set(compact('dataSet')); > > > > } > > > } > > > > Thanks for the help. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---