Hello, help please.
I'm going to write multiple rows into 2 tables of my DB using Rose::DB.
I.e., structures of tables are:
1) table Parents:
a) column id,
b) column name,
c) column child -> link to table Kids::id
2) table Kids:
a) column id,
b) column name
All the keys is OK, forget them please.
Can I prepare all the data (i.e. 2-3 Parents with 1-2 Kids) to write it in one circle for/while?
I read something about "linked initialization" of Rose::DB::Objects, but I don't 100% understood, how it works.
But I think my case is somewhere near.
I mean something like this:
my @data = ();
$data[0] = Persons->new(
'name' => "mr. Garret, the husband',
'child' => Kids->new('name' => 'Betty')
);
$data[1] = Persons->new(
'name' => "mrs. Garret, the wife",
'child' => Kids->new('name' => 'Betty') #yes, only one child is into DB
);
foreach my $person (@data) {
$person->save(cascade => 1);
}
I really don't understand, how it works in that case?
Will there be a multiple rows into table Kids in that case or there will be only one row?
What will be written into DB after that code in case that the DB is empty?