Rose-DB-Object
view release on metacpan
or search on metacpan
Changes
view on Meta::CPAN
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | * Non-persistent columns feature added.
* Made "where" an alias for the Manager's "query" parameter.
(Requested by Ask Bjørn Hansen)
* Documented restrictions on the Manager's "select" parameter.
* Fixed bug that prevented CURRENT_TIMESTAMP from being properly
inlined in queries sent to SQLite. (RT 37224)
* Fixed a memory leak. (Reported by Christopher Laco)
* The "cluck" error mode now correctly calls cluck() rather than
croak(). (Reported by Kevin McGrath)
* Added support for Oracle date/ time column keywords.
* Cascaded delete now properly cascades to one-to-one related objects.
(Reported by kittens)
0.770 (05.28.2008) - John Siracusa <siracusa @gmail .com>
* Added "iterator" method type, similar to "find" , to OneToMany
and ManyToMany. (Patch by Peter Karman - peknet @gmail .com)
* Updated the Loader documentation to describe an important
consideration when regenerating modules with make_modules().
* Improved error propagation in relationship methods. (Suggested
by Wiggins d'Anconia)
|
Changes
view on Meta::CPAN
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | * Added the with_column_triggers attribute to foreign keys and singular
relationships in order to keep columns and related objects in sync.
* Fixed a bug that caused some optional related objects to be improperly
transformed into required objects. (Reported by Ethan Rowe)
* Improved detection of errors when auto-loading related classes.
* Duplicate auto-created map record method names are now detected and
reported as a fatal error.
* Added and documented a return value for add_columns().
* Added module_preamble and module_postamble features to the Loader's
make_modules() method. (Patch by David Christensen)
* Made changes_only, cascade, and prepare_cached arguments to save()
also apply to *_on_save collections.
* Added test and prerequisite version for a Rose::DB bug that
prevented certain reserved words from being detected as primary
key columns in PostgreSQL. (Reported by Fred Cox)
* Baseline Oracle support added to the Loader. (Patch by Teodor Zlatanov)
* The clone() and clone_and_reset() methods now handle missing or
differently named accessor/mutator methods.
* QueryBuilder now supports eq/ne undef for is/is not null comparisons.
* Foreign key columns that are also primary key columns are no longer set
to undef when a foreign object is set to undef . (Reported by Ovid)
|
Changes
view on Meta::CPAN
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | * Added a "find" method type to one-to-many relationships for
ad-hoc queries.
* Added support for Informix's "datetime year to month" column type.
* Updated the dbh() method to be a more conventional proxy for ->db->dbh().
* The get_objects() and delete_objects() Manager methods now accept a lone
arrayref or hashref argument as a short way to specify the value of the
"query" parameter.
* Eliminated warning in the BigNum column type when the GMP math library
is not installed.
* Added a double precision column type and class for PostgreSQL.
* Fixed a bug that caused cascaded save() to fail to cascade beyond
a set-on-save related object.
* Improved reporting of errors in auto-loaded related modules.
* Fixed a bug that caused numeric columns to have invalid length
restrictions. (Reported by Fred Cox)
* Fixed many incorrect skip counts in the test suite when running against
PostgreSQL without CHKPASS support.
0.760 (01.16.2007) - John Siracusa <siracusa @gmail .com>
* Fixed a mistake in the test suite that caused spurious failures
|
Changes
view on Meta::CPAN
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | foreign_key_name_generator() method and the convention manager's
auto_foreign_key_name() method to avoid some name conflict bugs
and create a more sensible flow for foreign key naming.
(Suggested by Graham Barr)
* Added has_modified_children() has_loaded_related() methods to
Rose::DB::Object::Util.
* Added an init_with_column_value_pairs() helper method. (Requested
by Jonathan Vanasco)
* Modified child objects are now correctly detected and handled by
cascading save(). (Reported by Lucian Dragus)
* Fixed a bug that caused save( changes_only => 1, cascade => 1) to
fail in cases where a child object set a key column in the parent
object. (Reported by Lucian Dragus)
* Fixed a bug in the Manager that caused the with_objects parameter
to be ignored when the count_only parameter was set. (Reported
by Uwe Voelker)
* The column_values_as_*() helper methods no longer require the column_value_pairs() helper to also be imported. (Reported
by Jonathan Vanasco)
* Fixed a bug caused by blank lines in JSON and YAML output.
(Patch by Jonathan Vanasco)
|
Changes
view on Meta::CPAN
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | * The Loader's include_tables and exclude_tables attributes now accept
references to arrays of table names as well as regular expressions.
* The Loader's include_tables and exclude_tables attributes are now
case-insensitive by default .
* Fixed a bug that caused save() with sub -objects to fail in some cases.
(Reported by Wiggins d'Anconia)
* Added examples of the add_on_save relationship methods to the tutorial.
0.75 (08.10.2006) - John Siracusa <siracusa @gmail .com>
* Added a cascade option to save().
* Added auto-detection of one-to-one relationships to the Loader.
* The object_class parameter to Manager methods now defaults to the
return value of the object_class() class method.
* The soft() and referential_integrity() methods of the ManyToOne and
OneToOne relationship classes have been renamed to optional() and
required(), respectively. The old method names still work, but may
be removed at some later date. Also, the default values are now
determined by a new set of rules, rather than a constant.
* Passing invalid query parameters to Manager methods will now
cause a fatal error.
|
Changes
view on Meta::CPAN
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | * Fixed a bug that caused false boolean values to be ignored when an
object was loaded, modified, and then saved. (Patch by Cees Hek)
0.726 (05.17.2006) - John Siracusa <siracusa @gmail .com>
* Fixed incorrect skip count in t/spot-check-07.t
0.725 (05.17.2006) - John Siracusa <siracusa @gmail .com>
* Fixed a bug that caused self-referential many-to-many relationships to
fail during cascaded save() operations. (Reported by Michael Drozdov)
* The test suite now requires DBD::SQLite version 1.11 or later.
* Modified auto-init system to account for custom FetchHashKeyName
DBI settings.
0.724 (05.11.2006) - John Siracusa <siracusa @gmail .com>
* Added the replace_column() Metadata method.
* The add_now and add_on_save relationship methods now return
the number of items added when called in scalar context and
the list of items added when called in list context.
|
Changes
view on Meta::CPAN
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 | * Fixed a bug in QueryBuilder that prevented the ability to check
for null columns.
* Added the ability to query columns that are not SELECTed.
0.076 (10.05.2005) - John Siracusa <siracusa @gmail .com>
* Fixed a bug that caused incorrect counts in get_objects_count()
relationships.
* Added bulk update and delete methods to Manager.
* Added cascaded delete , plus a plea in the documentation for users
to do this in the database instead.
* Added "many to one" relationship and made it the new default
relationship type for foreign keys .
* Added *_now and *_on_save method types for foreign keys and
"... to one" relationships.
* Made get_set_on_save and delete_on_save the default auto method
types for foreign keys and "... to one" relationships.
* load() now returns the object itself on success, which allows
for the convenient $obj = MyObject->new( id => 123)->load;
* save() now returns the object itself on success, which allows
|
MANIFEST
view on Meta::CPAN
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | t/make-modules.t
t/ map -record-name-conflict.pl
t/multi-many-the-hard-way.t
t/multi-pk-sequences.t
t/nested-joins.t
t/one-to-many- reset .t
t/pk-fk-columns.t
t/pod.t
t/query-builder.t
t/rt-cpan-45836.t
t/save-cascade.t
t/sandbox/code-gen/generated-perl-test.pl
t/sandbox/code-gen/lib/.placeholder
t/sandbox/code-gen/make-modules.pl
t/sandbox/convention/convention-test-auto.pl
t/sandbox/convention/convention-test-loader.pl
t/sandbox/convention/convention-test.pl
t/sandbox/convention/lib/My/Auto/Color.pm
t/sandbox/convention/lib/My/Auto/Price.pm
t/sandbox/convention/lib/My/Auto/Product.pm
t/sandbox/convention/lib/My/Auto/ProductColors.pm
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | $self ->{MODIFIED_COLUMNS()} = {};
return $self || 1;
}
sub save
{
my ( $self , %args ) = @_ ;
my $meta = $self ->meta;
my $cascade =
exists $args { 'cascade' } ? $args { 'cascade' } :
$meta ->default_cascade_save;
if ( $self ->{ON_SAVE_ATTR_NAME()} || $cascade )
{
my $db = $args { 'db' } || $self ->db || return 0;
my $ret = $db ->begin_work;
$args { 'db' } ||= $db ;
unless ( $ret )
{
my $error = $db ->error;
$self ->error( ref $error ? $error : "Could not begin transaction before saving - $error" );
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | TRY:
{
local $@;
eval
{
my %did_set ;
my %code_args =
map { ( $_ => $args { $_ }) } grep { exists $args { $_ } }
qw(changes_only prepare_cached cascade) ;
my $todo = $self ->{ON_SAVE_ATTR_NAME()}{ 'pre' };
foreach my $fk_name ( keys %{ $todo ->{ 'fk' }})
{
my $code = $todo ->{ 'fk' }{ $fk_name }{ 'set' } or next ;
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | my $code = $item ->{ 'code' };
my $object = $item ->{ 'object' };
next if ( $did_set { 'fk' }{ $fk_name }{Rose::DB::Object::Util::row_id( $object )});
$code ->( $self , \ %code_args ) or die $self ->error;
}
}
if ( $cascade )
{
foreach my $fk ( $meta ->foreign_keys)
{
local $args { 'changes_only' } = 1 if ( $todo ->{ 'fk' }{ $fk ->name}{ 'set' });
my $foreign_object = $fk ->object_has_foreign_object( $self ) || next ;
if (Rose::DB::Object::Util::has_modified_columns( $foreign_object ) ||
Rose::DB::Object::Util::has_modified_children( $foreign_object ))
{
$Debug && warn "$self - save foreign " , $fk ->name, " - $foreign_object\n" ;
$foreign_object ->save( %args );
}
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | $code ->( $self , \ %code_args ) or die $self ->error;
}
if ( $code = $todo ->{ 'rel' }{ $rel_name }{ 'add' }{ 'code' })
{
$code ->( $self , \ %code_args ) or die $self ->error;
}
}
if ( $cascade )
{
foreach my $rel ( $meta ->relationships)
{
local $args { 'changes_only' } = 1 if ( $todo ->{ 'rel' }{ $rel ->name}{ 'set' });
my $related_objects = $rel ->object_has_related_objects( $self ) || next ;
foreach my $related_object ( @$related_objects )
{
if (Rose::DB::Object::Util::has_modified_columns( $related_object ) ||
Rose::DB::Object::Util::has_modified_children( $related_object ))
{
$Debug && warn "$self - save related " , $rel ->name, " - $related_object\n" ;
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 | my @pk_values = grep { defined } map { $self -> $_ () } @pk_methods ;
unless ( @pk_values == @pk_methods )
{
$self ->error( "Cannot delete " . ref ( $self ) . " without a primary key (" .
join ( ', ' , @pk_methods ) . ')' );
$self ->meta->handle_error( $self );
return 0;
}
if ( my $cascade = $args { 'cascade' })
{
unless ( exists $CASCADE_VALUES { $cascade })
{
Carp::croak "Illegal value for 'cascade' parameter: '$cascade'. " ,
"Valid values are 'delete', 'null', and '1'" ;
}
$cascade = $CASCADE_VALUES { $cascade };
my $mgr_error_mode = Rose::DB::Object::Manager->error_mode;
my ( $db , $started_new_tx , $error );
TRY:
{
local $@;
eval
{
$db = $self ->db;
my $meta = $self ->meta;
my $ret = $db ->begin_work;
unless ( defined $ret )
{
die 'Could not begin transaction before deleting with cascade - ' ,
$db ->error;
}
$started_new_tx = ( $ret == IN_TRANSACTION) ? 0 : 1;
unless ( $self ->{STATE_IN_DB()})
{
$self ->load
or die "Could not load in preparation for cascading delete: " ,
$self ->error;
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 | my $method = $meta ->column_accessor_method_name( $local_column );
my $value = $self -> $method ();
next REL unless ( defined $value );
push ( @query , $foreign_column => $value );
}
if ( $cascade eq 'delete' )
{
Rose::DB::Object::Manager->delete_objects(
db => $db ,
object_class => $relationship ->class,
where => \ @query );
}
elsif ( $cascade eq 'null' )
{
my %set = map { $_ => undef } values ( %$column_map );
Rose::DB::Object::Manager->update_objects(
db => $db ,
object_class => $relationship ->class,
set => \ %set ,
where => \ @query );
}
else { Carp::confess "Illegal cascade value '$cascade' snuck through" }
}
elsif ( $rel_type eq 'many to many' )
{
my $map_class = $relationship ->map_class;
my $map_from = $relationship ->map_from;
my $map_from_relationship =
$map_class ->meta->foreign_key( $map_from ) ||
$map_class ->meta->relationship( $map_from ) ||
Carp::confess "No foreign key or 'many to one' relationship " ,
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 | my $method = $meta ->column_accessor_method_name( $foreign_column );
my $value = $self -> $method ();
next REL unless ( defined $value );
push ( @query , $local_column => $value );
}
if ( $cascade eq 'delete' )
{
Rose::DB::Object::Manager->delete_objects(
db => $db ,
object_class => $map_class ,
where => \ @query );
}
elsif ( $cascade eq 'null' )
{
my %set = map { $_ => undef } keys ( %$key_columns );
Rose::DB::Object::Manager->update_objects(
db => $db ,
object_class => $map_class ,
set => \ %set ,
where => \ @query );
}
else { Carp::confess "Illegal cascade value '$cascade' snuck through" }
}
elsif ( $rel_type eq 'one to one' )
{
push ( @one_to_one_rels , $relationship );
}
}
my $dbh = $db ->dbh or die "Could not get dbh: " , $self ->error;
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 | my $method = $meta ->column_accessor_method_name( $local_column );
my $value = $self -> $method ();
next FK unless ( defined $value );
push ( @query , $foreign_column => $value );
}
if ( $cascade eq 'delete' )
{
Rose::DB::Object::Manager->delete_objects(
db => $db ,
object_class => $fk ->class,
where => \ @query );
}
elsif ( $cascade eq 'null' )
{
my %set = map { $_ => undef } values ( %$key_columns );
Rose::DB::Object::Manager->update_objects(
db => $db ,
object_class => $fk ->class,
set => \ %set ,
where => \ @query );
}
else { Carp::confess "Illegal cascade value '$cascade' snuck through" }
}
REL: foreach my $relationship ( @one_to_one_rels )
{
my $column_map = $relationship ->column_map;
my @query ;
foreach my $local_column ( keys %$column_map )
{
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 | my $method = $meta ->column_accessor_method_name( $local_column );
my $value = $self -> $method ();
next REL unless ( defined $value );
push ( @query , $foreign_column => $value );
}
if ( $cascade eq 'delete' )
{
Rose::DB::Object::Manager->delete_objects(
db => $db ,
object_class => $relationship ->class,
where => \ @query );
}
elsif ( $cascade eq 'null' )
{
my %set = map { $_ => undef } values ( %$column_map );
Rose::DB::Object::Manager->update_objects(
db => $db ,
object_class => $relationship ->class,
set => \ %set ,
where => \ @query );
}
else { Carp::confess "Illegal cascade value '$cascade' snuck through" }
}
if ( $started_new_tx )
{
$db ->commit or die $db ->error;
}
};
$error = $@;
}
if ( $error )
{
Rose::DB::Object::Manager->error_mode( $mgr_error_mode );
$self ->error( ref $error ? $error : "delete() with cascade - $error" );
$db ->rollback if ( $db && $started_new_tx );
$self ->meta->handle_error( $self );
return 0;
}
Rose::DB::Object::Manager->error_mode( $mgr_error_mode );
$self ->{STATE_IN_DB()} = 0;
return 1;
}
else
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 | Get or set the L<DBI> database handle contained in L<db|/db>.
|
lib/Rose/DB/Object.pm
view on Meta::CPAN
2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 |
$product ->save;
See the "making methods" sections of the L<Rose::DB::Object::Metadata::Relationship|Rose::DB::Object::Metadata::Relationship/ "MAKING METHODS" > and L<Rose::DB::Object::Metadata::ForeignKey|Rose::DB::Object::Metadata::ForeignKey/ "MAKING METHODS" > docum...
Valid parameters to L<save()|/save> are:
|
lib/Rose/DB/Object/Loader.pm
view on Meta::CPAN
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | {
croak "Illegal class prefix: $class_prefix" ;
}
$class_prefix .= '::' unless ( $class_prefix =~ /::$/);
}
local $self ->{ 'class_prefix' } = $class_prefix ;
my %save ;
if ( exists $args { 'db_class' })
{
my $db_class = delete $args { 'db_class' };
if ( $db && $db_class && $db_class ne $db ->class)
{
|
lib/Rose/DB/Object/MakeMethods/Generic.pm
view on Meta::CPAN
2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 | $self -> $local_method ( undef );
}
}
$to_save_pre = delete $self ->{ON_SAVE_ATTR_NAME()}{ 'pre' }{ 'fk' }{ $fk_name }{ 'set' };
$to_save_post = delete $self ->{ON_SAVE_ATTR_NAME()}{ 'post' }{ 'rel' }{ $fk_name }{ 'set' };
$self ->save or die $self ->error;
$deleted = $object -> delete ( @_ ) or die $object ->error;
if ( $started_new_tx )
{
$db ->commit or die $db ->error;
}
$self ->{ $key } = undef ;
|
lib/Rose/DB/Object/Metadata.pm
view on Meta::CPAN
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | allow_inline_column_values => { default => 0 },
is_initialized => { default => 0 },
is_auto_initializating => { default => 0 },
allow_auto_initialization => { default => 0 },
was_auto_initialized => { default => 0 },
initialized_foreign_keys => { default => 0 },
default_load_speculative => { default => 0 },
auto_load_related_classes => { default => 1 },
default_update_changes_only => { default => 0 },
default_insert_changes_only => { default => 0 },
default_cascade_save => { default => 0 },
default_smart_modification => { default => 0 },
include_predicated_unique_indexes => { default => 0 },
],
'array --get_set_inited' =>
[
'columns_ordered' ,
'nonpersistent_columns_ordered' ,
]
);
|
lib/Rose/DB/Object/Metadata.pm
view on Meta::CPAN
5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 | If a L<Rose::DB::Object::ConventionManager>-derived class name is passed, a new object of that class is created with its L<meta|Rose::DB::Object::ConventionManager/meta> attribute set to this metadata object. Then it is used as the convention manage...
If a convention manager name is passed, then the corresponding class is looked up in the L<convention manager class map |convention_manager_classes>, a new object of that class is constructed, its L<meta|Rose::DB::Object::ConventionManager/meta> attri...
See the L<Rose::DB::Object::ConventionManager> documentation for more information on convention managers.
|
lib/Rose/DB/Object/Tutorial.pod
view on Meta::CPAN
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 | $p -> delete ;
The list of prices for the product can also be set to an empty list, which will have the effect of deleting all associated prices when the product is saved.
$p ->prices([]);
$p ->save;
$p -> delete ;
Finally, the L< delete ()|Rose::DB::Object/ delete > method can actually automate this process, and do it all inside a transaction as well.
$p -> delete ( cascade => 1);
Again, the recommended approach is to use triggers inside the database itself. But if necessary, these other approaches will work too. |
lib/Rose/DB/Object/Tutorial.pod
view on Meta::CPAN
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 | Passing a reference to an empty array will remove all colors associated with a particular product by deleting all the mapping table entries.
$p ->colors([]);
$p ->save;
Finally, the same caveats L<described earlier|/ "Cascading delete" > about deleting products that have associated prices apply to colors as well. Again, I recommend using a trigger in the database to handle this, but L<Rose::DB::Object>'s cascading de...
$p -> delete ( cascade => 1);
|
t/benchmarks/lib/MyTest/CDBI/Complex/Product.pm
view on Meta::CPAN
21 22 23 24 25 26 27 28 29 30 31 32 33 | __PACKAGE__->has_a( last_modified => 'DateTime' ,
inflate => sub { $MyTest::CDBI::Base::DB ->parse_datetime( shift ) },
deflate => sub { $MyTest::CDBI::Base::DB ->format_datetime( shift ) });
__PACKAGE__->has_a( published => 'DateTime' ,
inflate => sub { $MyTest::CDBI::Base::DB ->parse_datetime( shift ) },
deflate => sub { $MyTest::CDBI::Base::DB ->format_datetime( shift ) });
__PACKAGE__->has_a( category_id => 'MyTest::CDBI::Complex::Category' );
__PACKAGE__->has_many( code_names => 'MyTest::CDBI::Complex::CodeName' , { cascade => 'None' });
1;
|
t/benchmarks/lib/MyTest/CDBI/Simple/Product.pm
view on Meta::CPAN
9 10 11 12 13 14 15 16 17 18 19 20 21 | __PACKAGE__->table( 'rose_db_object_test_products' );
__PACKAGE__->columns( Primary => 'id' );
__PACKAGE__->columns( Essential => qw(category_id date_created fk1 fk2 fk3 id last_modified name published status) );
__PACKAGE__->has_a( category_id => 'MyTest::CDBI::Simple::Category' );
__PACKAGE__->has_many( code_names => 'MyTest::CDBI::Simple::CodeName' , { cascade => 'None' });
1;
|
t/benchmarks/lib/MyTest/CDBI/Sweet/Complex/Product.pm
view on Meta::CPAN
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | __PACKAGE__->has_a( last_modified => 'DateTime' ,
inflate => sub { $MyTest::CDBI::Base::DB ->parse_datetime( shift ) },
deflate => sub { $MyTest::CDBI::Base::DB ->format_datetime( shift ) });
__PACKAGE__->has_a( published => 'DateTime' ,
inflate => sub { $MyTest::CDBI::Base::DB ->parse_datetime( shift ) },
deflate => sub { $MyTest::CDBI::Base::DB ->format_datetime( shift ) });
__PACKAGE__->has_a( category_id => 'MyTest::CDBI::Sweet::Complex::Category' );
__PACKAGE__->has_many( code_names => 'MyTest::CDBI::Sweet::Complex::CodeName' , { cascade => 'None' });
my $meta = __PACKAGE__->meta_info( has_many => 'code_names' );
$meta ->args->{ 'foreign_key' } = 'product_id' ;
1;
|
t/benchmarks/lib/MyTest/CDBI/Sweet/Simple/Product.pm
view on Meta::CPAN
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | __PACKAGE__->table( 'rose_db_object_test_products' );
__PACKAGE__->columns( Primary => 'id' );
__PACKAGE__->columns( Essential => qw(category_id date_created fk1 fk2 fk3 id last_modified name published status) );
__PACKAGE__->has_a( category_id => 'MyTest::CDBI::Sweet::Simple::Category' );
__PACKAGE__->has_many( code_names => 'MyTest::CDBI::Sweet::Simple::CodeName' , { cascade => 'None' });
my $meta = __PACKAGE__->meta_info( has_many => 'code_names' );
$meta ->args->{ 'foreign_key' } = 'product_id' ;
1;
|
t/db-object-relationship.t
view on Meta::CPAN
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | $o ->fkone(1);
$o ->fk2(2);
$o ->fk3(3);
$o ->save;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$o -> delete ( cascade => 'null' );
};
ok($@, "delete cascade null 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyPgOtherObject' );
is( $count , 2, "delete cascade rollback confirm 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyPgOtherObject2' );
is( $count , 3, "delete cascade rollback confirm 2 - $db_type" );
ok( $o -> delete ( cascade => 'delete' ), "delete cascade delete 1 - $db_type" );
$o = MyPgObject->new( id => 99)->load;
$o ->fkone(11);
$o ->fk2(12);
$o ->fk3(13);
$o ->save;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$o -> delete ( cascade => 'null' );
};
ok($@, "delete cascade null 2 - $db_type" );
ok( $o -> delete ( cascade => 'delete' ), "delete cascade delete 2 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyPgColorMap' );
is( $count , 0, "delete cascade confirm 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyPgOtherObject2' );
is( $count , 0, "delete cascade confirm 2 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyPgOtherObject' );
is( $count , 0, "delete cascade confirm 3 - $db_type" );
eval { $o ->meta->alias_column( nonesuch => 'foo' ) };
ok($@, "alias_column() nonesuch - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | $o = MyPgObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 10 - $db_type" );
$co = MyPgOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 11 - $db_type" );
$o -> delete ( cascade => 1);
$o = MyPgObject->new( id => 200,
name => 'Rose' ,
flag => 1);
ok( $o ->other_obj_on_save( k1 => 51, k2 => 52, k3 => 53), "set foreign key object on save 12 - $db_type" );
$co = MyPgObject->new( id => 200);
ok(! $co ->load( speculative => 1), "set foreign key object on save 13 - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | $o = MyPgObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 18 - $db_type" );
$co = MyPgOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 19 - $db_type" );
$o -> delete ( cascade => 1);
$o = MyPgObject->new( id => 500,
name => 'Kip' ,
flag => 1);
$o ->other_obj_on_save( k1 => 7, k2 => 8, k3 => 9);
|
t/db-object-relationship.t
view on Meta::CPAN
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 | $o ->fk3(3);
$o ->save;
my $ret ;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$ret = $o -> delete ( cascade => 'null' );
};
ok( $ret || $@, "delete cascade null 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyMySQLOtherObject2' );
is( $count , 3, "delete cascade rollback confirm 2 - $db_type" );
$o = MyMySQLObject->new( id => 99)->load;
$o ->fk1(11);
$o ->fk2(12);
$o ->fk3(13);
$o ->save;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$ret = $o -> delete ( cascade => 'null' );
};
ok( $ret || $@, "delete cascade null 2 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyMySQLColorMap' );
is( $count , 3, "delete cascade confirm 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyMySQLOtherObject2' );
is( $count , 3, "delete cascade confirm 2 - $db_type" );
eval { $o ->meta->alias_column( nonesuch => 'foo' ) };
ok($@, "alias_column() nonesuch - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 | $o = MyMySQLObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 10 - $db_type" );
$co = MyMySQLOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 11 - $db_type" );
$o -> delete ( cascade => 1);
$o = MyMySQLObject->new( id => 200,
name => 'Rose' ,
flag => 1);
ok( $o ->other_obj_on_save( k1 => 51, k2 => 52, k3 => 53), "set foreign key object on save 12 - $db_type" );
$co = MyMySQLObject->new( id => 200);
ok(! $co ->load( speculative => 1), "set foreign key object on save 13 - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 | $o = MyMySQLObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 18 - $db_type" );
$co = MyMySQLOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 19 - $db_type" );
$o -> delete ( cascade => 1);
$o = MyMySQLObject->new( id => 500,
name => 'Kip' ,
flag => 1);
$o ->other_obj_on_save( k1 => 7, k2 => 8, k3 => 9);
|
t/db-object-relationship.t
view on Meta::CPAN
2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 | ok(MyMySQLColorMap->new( obj_id => 60, color_id => 8)->load( speculative => 1),
"add 2 many to many on save 33 - $db_type" );
$sth = $color ->db->dbh->prepare( 'SELECT COUNT(*) FROM rose_db_object_colors_map WHERE obj_id = 60' );
$sth ->execute;
$count = $sth ->fetchrow_array;
is( $count , 5, "add 2 many to many on save 34 - $db_type" );
$o = MyMySQLObject->new( name => '1to1bug' ,
fk1 => 10,
fk2 => 20,
fk3 => 30,
other_obj_otoo =>
{
name => '1to1bugfo' ,
k1 => 10,
k2 => 20,
k3 => 30,
});
$o ->save;
$o = MyMySQLObject->new( id => $o ->id)->load;
ok( defined $o ->other_obj_otoo, "delete(cascade => 1) one to one prep - $db_type" );
$o = MyMySQLObject->new( id => $o ->id);
$o -> delete ( cascade => 1);
ok(!MyMySQLOtherObject->new( k1 => 10, k2 => 20, k3 => 30)->load( speculative => 1),
"delete(cascade => 1) one to one delete - $db_type" );
$o2 = MyMySQLOtherObject2->new( name => 'B' , pid => 11);
$o2 ->save;
$o = MyMySQLObject->new( name => 'John' , id => 12);
$o ->add_other2_objs2( $o2 );
$o2 ->name( 'John2' );
|
t/db-object-relationship.t
view on Meta::CPAN
3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 | $o ->fkone(1);
$o ->fk2(2);
$o ->fk3(3);
$o ->save;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$o -> delete ( cascade => 'null' );
};
ok($@, "delete cascade null 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyInformixOtherObject' );
is( $count , 2, "delete cascade rollback confirm 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyInformixOtherObject2' );
is( $count , 3, "delete cascade rollback confirm 2 - $db_type" );
ok( $o -> delete ( cascade => 'delete' ), "delete cascade delete 1 - $db_type" );
$o = MyInformixObject->new( id => 99)->load;
$o ->fkone(11);
$o ->fk2(12);
$o ->fk3(13);
$o ->save;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$o -> delete ( cascade => 'null' );
};
ok($@, "delete cascade null 2 - $db_type" );
ok( $o -> delete ( cascade => 'delete' ), "delete cascade delete 2 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyInformixColorMap' );
is( $count , 0, "delete cascade confirm 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyInformixOtherObject2' );
is( $count , 0, "delete cascade confirm 2 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MyInformixOtherObject' );
is( $count , 0, "delete cascade confirm 3 - $db_type" );
eval { $o ->meta->alias_column( nonesuch => 'foo' ) };
ok($@, "alias_column() nonesuch - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 | $o = MyInformixObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 10 - $db_type" );
$co = MyInformixOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 11 - $db_type" );
$o -> delete ( cascade => 1);
$o = MyInformixObject->new( id => 200,
name => 'Rose' ,
flag => 1);
ok( $o ->other_obj_on_save( k1 => 51, k2 => 52, k3 => 53), "set foreign key object on save 12 - $db_type" );
$co = MyInformixObject->new( id => 200);
ok(! $co ->load( speculative => 1), "set foreign key object on save 13 - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 | $o = MyInformixObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 18 - $db_type" );
$co = MyInformixOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 19 - $db_type" );
$o -> delete ( cascade => 1);
$o = MyInformixObject->new( id => 500,
name => 'Kip' ,
flag => 1);
$o ->other_obj_on_save( k1 => 7, k2 => 8, k3 => 9);
|
t/db-object-relationship.t
view on Meta::CPAN
4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 | $o ->fkone(1);
$o ->fk2(2);
$o ->fk3(3);
$o ->save;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$o -> delete ( cascade => 'null' );
};
ok($@, "delete cascade null 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MySQLiteOtherObject' );
is( $count , 2, "delete cascade rollback confirm 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MySQLiteOtherObject2' );
is( $count , 3, "delete cascade rollback confirm 2 - $db_type" );
ok( $o -> delete ( cascade => 'delete' ), "delete cascade delete 1 - $db_type" );
$o = MySQLiteObject->new( id => 99)->load;
$o ->fkone(11);
$o ->fk2(12);
$o ->fk3(13);
$o ->save;
eval
{
local $o ->dbh->{ 'PrintError' } = 0;
$o -> delete ( cascade => 'null' );
};
ok($@, "delete cascade null 2 - $db_type" );
ok( $o -> delete ( cascade => 'delete' ), "delete cascade delete 2 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MySQLiteColorMap' );
is( $count , 0, "delete cascade confirm 1 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MySQLiteOtherObject2' );
is( $count , 0, "delete cascade confirm 2 - $db_type" );
$count =
Rose::DB::Object::Manager->get_objects_count(
db => $o ->db,
object_class => 'MySQLiteOtherObject' );
is( $count , 0, "delete cascade confirm 3 - $db_type" );
eval { $o ->meta->alias_column( nonesuch => 'foo' ) };
ok($@, "alias_column() nonesuch - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 | $o = MySQLiteObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 10 - $db_type" );
$co = MySQLiteOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 11 - $db_type" );
$o -> delete ( cascade => 1);
$o = MySQLiteObject->new( id => 200,
name => 'Rose' ,
flag => 1);
ok( $o ->other_obj_on_save( k1 => 51, k2 => 52, k3 => 53), "set foreign key object on save 12 - $db_type" );
$co = MySQLiteObject->new( id => 200);
ok(! $co ->load( speculative => 1), "set foreign key object on save 13 - $db_type" );
|
t/db-object-relationship.t
view on Meta::CPAN
5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 | $o = MySQLiteObject->new( id => 200);
$o ->load;
ok(! defined $o ->other_obj_on_save, "set foreign key object on save 18 - $db_type" );
$co = MySQLiteOtherObject->new( k1 => 51, k2 => 52, k3 => 53);
ok(! $co ->load( speculative => 1), "set foreign key object on save 19 - $db_type" );
$o -> delete ( cascade => 1);
$o = MySQLiteObject->new( id => 500,
name => 'Kip' ,
flag => 1);
$o ->other_obj_on_save( k1 => 7, k2 => 8, k3 => 9);
|
t/make-modules.ext
view on Meta::CPAN
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | sort { $a ->price <=> $b ->price } $p ->prices) . '; ' .
join ( ', ' , map { $_ ->name } sort { $a ->name cmp $b ->name } $p ->colors) . '; ' ;
my $c = $color_class ->new( name => 'red' )->load;
$ret .= $c ->name . ': ' . $c ->code, '; ' ;
print $ret , "\n" ;
my $v = $p ->vendor;
$p -> delete ( cascade => 1);
$v -> delete ;
$product_manager_class ->delete_products( all => 1);
$color_manager_class ->delete_colors( all => 1);
|
t/one-to-many-reset.t
view on Meta::CPAN
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
my $artist_class = $class_prefix . '::RoseDbObjectArtist' ;
my $album_class = $class_prefix . '::RoseDbObjectAlbum' ;
Rose::DB::Object::Metadata->dbi_prepare_cached( $db_type eq 'informix' ? 0 : 1);
my $albums_method = 'rose_db_object_albums' ;
foreach my $cascade (0, 1)
{
my @cascade = $cascade ? ( cascade => 1) : ();
my $album = $album_class ->new( id => 1, title => 'album1' );
$album ->save();
my $artist = $artist_class ->new( id => 1, name => 'Rage' );
$artist -> $albums_method ( $album ->id);
$artist ->save( @cascade );
ok( $artist , "$cascade saved artist with albums - $db_type" );
$artist -> $albums_method ( $album ->id);
$artist ->save( @cascade );
ok( $artist , "$cascade re-saved artist albums = $db_type" );
$artist = $artist_class ->new( id => $artist ->id)->load;
is( scalar @{ $artist -> $albums_method () ||[]}, 1, "$cascade Check artist albums count - $db_type" );
is( $artist -> $albums_method ()->[0]->id, $album ->id, "$cascade Check artist album ids - $db_type" );
my @albums = $artist -> $albums_method ();
$artist -> $albums_method ( @albums );
$artist ->save;
$artist -> $albums_method ( @albums );
$artist ->save;
$artist = $artist_class ->new( id => $artist ->id)->load;
is( scalar @{ $artist -> $albums_method () ||[]}, 1, "$cascade Check artist albums count 2 - $db_type" );
is( $artist -> $albums_method ()->[0]->id, $album ->id, "$cascade Check artist album ids 2 - $db_type" );
$artist -> delete ( cascade => 1);
}
}
BEGIN
{
our %Have ;
|
t/save-cascade.t
view on Meta::CPAN
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
my $p = $product_class ->new( name => 'p1' , vendor => { name => 'v1' });
$p ->save;
$p = $product_class ->new( id => $p ->id)->load;
my $v = $p ->vendor;
$v ->name( 'v1.1' );
$p ->save( cascade => 1);
$v = $vendor_class ->new( id => $v ->id)->load;
is( $v ->name, 'v1.1' , "cascade fk 1.$i - $db_type" );
$p ->prices([ { price => 1.25 } ]);
$p ->save;
$p = $product_class ->new( id => $p ->id)->load;
my $price = $p ->prices->[0];
is( $price ->price, 1.25, "cascade one-to-many 1.$i - $db_type" );
is( $price ->region, 'US' , "cascade one-to-many 2.$i - $db_type" );
$price ->region( 'UK' );
$p ->add_prices({ price => 4.25 });
$p ->save( cascade => 1);
$price = $price_class ->new( price_id => $price ->price_id)->load;
is( $price ->region, 'UK' , "cascade one-to-many 3.$i - $db_type" );
$price = ( sort { $a ->price <=> $b ->price } @{ $p ->prices})[-1];
is( $price ->price, 4.25, "cascade one-to-many 4.$i - $db_type" );
is( $price ->region, 'US' , "cascade one-to-many 5.$i - $db_type" );
$p ->colors([ { code => 'f00' , name => 'red' } ]);
$p ->save;
$p = $product_class ->new( id => $p ->id)->load;
my $color = $p ->colors->[0];
is( $color ->code, 'f00' , "cascade many-to-many 1.$i - $db_type" );
is( $color ->name, 'red' , "cascade many-to-many 2.$i - $db_type" );
$color ->name( 'r3d' );
$p ->add_colors({ code => '0f0' , name => 'green' });
$p ->save( cascade => 1);
$color = $color_class ->new( code => $color ->code)->load;
is( $color ->name, 'r3d' , "cascade many-to-many 3.$i - $db_type" );
$color = ( sort { $a ->name cmp $b ->name } @{ $p ->colors})[0];
is( $color ->code, '0f0' , "cascade many-to-many 4.$i - $db_type" );
is( $color ->name, 'green' , "cascade many-to-many 5.$i - $db_type" );
$p ->dbh-> do ( 'DELETE FROM product_colors' );
$p ->dbh-> do ( 'DELETE FROM colors' );
$p ->dbh-> do ( 'DELETE FROM prices' );
$p ->dbh-> do ( 'DELETE FROM products' );
$p ->dbh-> do ( 'DELETE FROM vendors' );
}
}
BEGIN
|
t/spot-check-12.t
view on Meta::CPAN
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | my $c = Clients->new( name => 'c1' );
$c ->load;
my $a = Addresses->new( client_id => $c ->id, street => 's1' );
$c ->address( $a );
ok( $c ->save( cascade => 1, changes_only => 1 ), 'save cascade changes only' );
$c = Rose::DB::Object::Manager->get_objects(
object_class => 'Clients' ,
with_objects => 'address' )->[0];
ok(! keys %{ $c ->{MODIFIED_COLUMNS()} || {} }, 'check modified columns' );
ok(has_loaded_related( $c , 'address' ), 'has_loaded_related() 1' );
ok(has_loaded_related( object => $c , relationship => 'address' ), 'has_loaded_related() 2' );
$c ->address->street( 's2' );
ok( $c ->save( cascade => 1, changes_only => 1), 'save cascade changes only - loaded with Manager' );
$a = Addresses->new( id => $a ->id)->load;
is( $a ->street, 's2' , 'save cascade changes only - check' );
}
END
{
if (have_db( 'sqlite_admin' ))
{
my $dbh = get_dbh( 'sqlite_admin' );
local $dbh ->{ 'RaiseError' } = 0;
local $dbh ->{ 'PrintError' } = 0;
|