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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---