Friday, August 27, 2010

Problem with simple SaveAll

Hi folks,

i do an import from xml-data and have finally succsefully extracted my
data. So now I want to save its with saveAll and nothing arrives in my
database (Mysql innodb)

This ist what I do:

model validation rules:
var $validate = array(
'hotel_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update'
operations
),
),
'leistungsbeschreibung_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update'
operations
),
),
'aibeschreibung' => array(
'notempty' => array(
'rule' => array('notempty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update'
operations
),
),
);

extracted data array I want to save:

var_dump($data['Allinclusive']);

gives me:

array
0 =>
array
'hotel_id' => string '1' (length=1)
'leistungsbeschreibung_id' => string '1' (length=1)
'aibeschreibung' => string 'Vollpension in Buffetform mit
Getränken (Mineralwasser, Tischwein, Erfrischungsgetränke und
Bier).' (length=100)
'aiart' => string 'Vollpension' (length=11)
'id' => string '' (length=0)
1 =>
array
'hotel_id' => string '1' (length=1)
'leistungsbeschreibung_id' => string '1' (length=1)
'aibeschreibung' => string 'Von 08:00-24:00 Uhr alkoholische und
nicht-alkoholische Getränke an der Hotelbar (ausgenommen: teurer Wein,
Sekt und Champagner), Kaffee/Tee und Gebäck von 15:30-17:30 Uhr an der
Salonbar.' (length=190)
'aiart' => string 'All Inclusive' (length=13)
'id' => string '' (length=0)
2 =>
array
'hotel_id' => string '1' (length=1)
'leistungsbeschreibung_id' => string '1' (length=1)
'aibeschreibung' => string 'Alle Getränke und Mahlzeiten an der
Beachbar/-club.' (length=52)
'aiart' => string 'Nicht in All Inclusive enthalten' (length=32)
'id' => string '' (length=0)


As you can see I have the data for three datasets in an numeric array.

Im my controller:
if(isset($data['Allinclusive'])) $err = $this->Hotel-
>Leistungsbeschreibung->Allinclusive-
>saveAll($data['Allinclusive']);
var_dump($err);

$err is true, but nothing is saved to my database.
Why oh why?

Cookbook says:
http://book.cakephp.org/view/1031/Saving-Your-Data
"Not that we are passing $data['Article'] instead of usual $data. When
saving multiple records of same model the records arrays should be
just numerically indexed without the model key." I guess the "Not" is
a typo and should be "Note". However exactly my example is shown here,
except that I call the saveAll through my related models, bit without
savinbg any of them.

So is calling in my hotels_controller.php
$this->Hotel->Leistungsbeschreibung->Allinclusive-
>saveAll($data['Allinclusive']);
the same like calling
$this->Allinclusive->saveAll($data['Allinclusive']);
form the allincluves_controller.php?

I thought yes, but obviously something isn't working at all.

Thanks in advance for any hints!

Anja

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: