You're probably missing the correct display field: class Donor { var $displayField = 'first_name'; }
and class Cause { var $displayField = 'cause_title'; } Note that 'cause' is superfluous in 'cause_title'. Why not just 'title'? On May 6, 4:22 pm, swiftguy <vikram....@gmail.com> wrote: > Hello Experts, > > Trying out a module where in donations for a social cause will be > accepted through a webform. For every donation record we need to > accept the donor_id,cause_id,amount being donated. In the Donations > Add form instead of displaying the actual donor_id we want to display > its corresponding Donor.first_name (this should be the drop down). > Similarly instead of displaying cause_id we want to display the > Cause.cause_title in the drop down. This way the user will be easily > create a donation record. > > The concerned DB table structures,model,controller and view functions > are listed below. > > Kindly help me out. Thanks in advance. > > Donations Module => Model (donation.php) > ========================================= > <?php > class Donation extends AppModel { > > var $name = 'Donation'; > > //The Associations below have been created with all possible keys, > those that are not needed can be removed > var $hasOne = array( > 'Cause' => array( > 'className' => 'Cause', > 'foreignKey' => 'cause_id', > 'dependent' => false, > 'conditions' => '', > 'fields' => '', > 'order' => '' > ), > 'Donor' => array( > 'className' => 'Donor', > 'foreignKey' => 'donor_id', > 'dependent' => false, > 'conditions' => '', > 'fields' => '', > 'order' => '' > ) > ); > > } > > ?> > > Donations Module => Controller (Add function) > ============================================= > function add() { > if (!empty($this->data)) { > $this->Donation->create(); > if ($this->Donation->save($this->data)) { > $this->Session->setFlash(__('The Donation has been saved', true)); > $this->redirect(array('action'=>'index'));} else { > > $this->Session->setFlash(__('The Donation could not be saved. Please, > try again.', true));} > } > > $donors = $this->Donation->Donor->find('list'); > $causes = $this->Donation->Cause->find('list'); > $this->set(compact('donors', 'causes')); > > } > > Donations Module => View (add.ctp) > ================================== > > <div class="donations form"> > <?php echo $form->create('Donation');?> > <fieldset> > <legend><?php __('Add Donation');?></legend> > <?php > echo $form->input('donor_id'); > echo $form->input('cause_id'); > ?> > </fieldset> > <?php echo $form->end('Submit');?> > </div> > <div class="actions"> > <ul> > <li><?php echo $html->link(__('List Donations', true), array > ('action'=>'index'));?></li> > </ul> > </div> > > MySQL Table Structures > ============= > create table causes ( > id int(11) auto_increment, > cause_title varchar(255), > cause_desc text, > funds_needed int(11), > funds_collected int(11), > cause_status varchar(255), > cause_snaps text, > primary key(id)); > > create table donors ( > id int(11) auto_increment, > first_name varchar(255), > last_name varchar(255), > surname varchar(255), > address text, > city varchar(255), > state varchar(255), > country varchar(255), > cause_id int(11), > primary key(id)); > > create table donations( > id int(11) auto_increment, > donor_id int(11), > cause_id(11), > amount int(11), > primary key(id)); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---