I'm doing a Member, Attendance project for church with the following
schema below:
And I'm able to save from both end member, and attendance, but the how
do I deal with attendances_members.offering on the link table.
I'm able to show it in the view and save, but if I edit attendance,
the link record is recreated and the previously populated
attendances_members.offering is gone.
Please help.
create table members (
id int not null auto_increment primary key,
first_name varchar(40) not null,
last_name varchar(40) not null,
date_of_birth date
);
create table attendances (
id int not null auto_increment primary key,
attend_date date not null
);
create table attendances_members (
id int not null auto_increment primary key,
member_id int not null,
attendance_id int not null,
offering decimal(6,2),
primary key (id)
);
Model:
attendance.php
<?php
/*
* Created on Sep 20, 2008
* By: susantan
* File: attendance.php
*
*/
class Attendance extends AppModel {
var $name = 'Attendance';
var $hasAndBelongsToMany = array('Member');
}
?>
member.php:
<?php
class Member extends AppModel {
var $name = 'Member';
var $hasAndBelongsToMany = array('Attendance');
}
?>
Controllers:
attendances_controller.php:
<?php
class AttendancesController extends AppController {
var $name = 'Attendances';
var $helpers = array('Html', 'Form');
function add() {
if (!empty($this->data)) {
$this->Attendance->create();
if ($this->Attendance->save($this->data)) {
$this->Session->setFlash(__('The Attendance has
been saved',
true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Attendance
could not be saved.
Please, try again.', true));
}
}
$members = $this->Attendance->Member-
>find('list',array('fields'=>'Member.first_name'));
$this->set(compact('members'));
}
?>
members_controller.php:
<?php
class MembersController extends AppController {
var $name = 'Members';
var $helpers = array('Html', 'Form');
function add() {
if (!empty($this->data)) {
$this->Member->create();
if ($this->Member->save($this->data)) {
$this->Session->setFlash(__('The Member has
been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Member could
not be saved.
Please, try again.', true));
}
}
$attendances = $this->Member->Attendance->find('list');
$this->set(compact('attendances'));
}
views:
attendances/add.ctp:
<div class="attendances form">
<?php echo $form->create('Attendance');?>
<fieldset>
<legend><?php __('Add Attendance ..');?></legend>
<?php
echo $form->input('attend_date');
echo $form-
>input('Member',array('type'=>'select','multiple'=>'checkbox'));
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---