I've done a lot of searching and reading, but I can't seem to figure out
the best way to handle this. Any advice would be appreciated:
I have a Customer model and a Departure model that have a HABTM
relationship. (Customers can sign up for multiple Departures.) I need to
keep track of the status for each of these associations (i.e. a Customer
can be 'booked' for Departure #1, but may only be 'penciled-in' for
Departure #2). I created a table, customer_departure_statuses, that holds
all of the possible statuses for a customer_departure object.
I have created a Customers_departures table that holds the following fields:
id
customer_id
departure_id
customer_departure_status_id
(Note: there are other fields in the customers_departures table, but they
are nullable and don't seem to have an impact on my problem.)
Right now, I have $hasAndBelongsToMany defined in each of the three models:
Customer, Departure, CustomerDepartureStatus. Here is how the association
is defined in the Departure model:
public $hasAndBelongsToMany = array(
'Customer' => array(
'className' => 'Customer',
'joinTable' => 'customers_departures',
'foreignKey' => 'departure_id',
'associationForeignKey' => 'customer_id',
'unique' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'CustomerDepartureStatus' => array(
'className' => 'CustomerDepartureStatus',
'joinTable' => 'customers_departures',
'foreignKey' => 'departure_id',
'associateForeignKey' => 'customer_departure_status_id',
'unique' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
)
I have the following $data set in an array:
Array
(
[Customer] => Array
(
[id] => 2
[person_id] => 15
[passportinformation] => passport info
[birthdate] => 1999-01-01 10:14:00
[placeofbirth] => The North Pole
[height] => 5'6"
[inseam] => 28
[bikenotes] => This is a bike note
[medical_need_id] => 1
[dietary_need_id] => 1
[referral_type_id] => 1
[passport_name] =>
[issue_date] =>
[expire_date] =>
[gender_id] => 1
)
[Departure] => Array
(
[id] => 1
[startdate] => 2014-05-01
[enddate] => 2014-05-08
[product_id] => 1
[departure_status_id] => 1
[CustomersDeparture] => Array
(
[id] => 1
[customer_id] => 5
[departure_id] => 1
[room_request_id] =>
[room_assignment_id] =>
[bike_id] =>
[customer_departure_status_id] => 1
)
)
[CustomerDepartureStatus] => Array
(
[id] => 1
[name] => Pencil In
[CustomersDeparture] => Array
(
[id] => 1
[customer_id] => 5
[departure_id] => 1
[room_request_id] =>
[room_assignment_id] =>
[bike_id] =>
[customer_departure_status_id] => 1
)
)
)
When I try to run this line of code - $this->Person->Customer->saveAll($data) -
I get the following error:
*Error: *
SQLSTATE[HY000]: General error: 1364 Field
'customer_departure_status_id' doesn't have a default value
(Note: This is called from the Person controller, which Customer $belongsTo. I
don't think this is influencing the save call, but I've included the
information just in case it is relevant.)
I've started reading up on the hasMany through option
<http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany-through-the-join-model>,
but I'm not sure if that is exactly what I need or not. Am I doing this
right? If so, what do I need to do to track down the error that I'm getting?
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.