[Bast-commits] r5097 - in DBIx-Class/0.08/trunk: lib/DBIx/Class
lib/DBIx/Class/Relationship t t/lib t/lib/DBICTest/Schema
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Mon Nov 10 23:09:23 GMT 2008
Author: ribasushi
Date: 2008-11-10 23:09:23 +0000 (Mon, 10 Nov 2008)
New Revision: 5097
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/BelongsTo.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
DBIx-Class/0.08/trunk/t/66relationship.t
DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/ForceForeign.pm
DBIx-Class/0.08/trunk/t/lib/sqlite.sql
Log:
belongs_to relationships are explicitly flagged by default, to aid the DBIC SQLT parser (by abraxxa)
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/BelongsTo.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/BelongsTo.pm 2008-11-10 23:04:43 UTC (rev 5096)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/BelongsTo.pm 2008-11-10 23:09:23 UTC (rev 5097)
@@ -9,6 +9,11 @@
sub belongs_to {
my ($class, $rel, $f_class, $cond, $attrs) = @_;
+
+ # assume a foreign key contraint unless defined otherwise
+ $attrs->{is_foreign_key_constraint} = 1
+ if not exists $attrs->{is_foreign_key_constraint};
+
# no join condition or just a column name
if (!ref $cond) {
$class->ensure_class_loaded($f_class);
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2008-11-10 23:04:43 UTC (rev 5096)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2008-11-10 23:09:23 UTC (rev 5097)
@@ -843,7 +843,7 @@
#warn "$self $k $for $v";
unless ($for->has_column_loaded($v)) {
if ($for->in_storage) {
- $self->throw_exception("Column ${v} not loaded on ${for} trying to reolve relationship");
+ $self->throw_exception("Column ${v} not loaded on ${for} trying to resolve relationship");
}
return $UNRESOLVABLE_CONDITION;
}
Modified: DBIx-Class/0.08/trunk/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/trunk/t/66relationship.t 2008-11-10 23:04:43 UTC (rev 5096)
+++ DBIx-Class/0.08/trunk/t/66relationship.t 2008-11-10 23:09:23 UTC (rev 5097)
@@ -7,7 +7,7 @@
my $schema = DBICTest->init_schema();
-plan tests => 67;
+plan tests => 69;
# has_a test
my $cd = $schema->resultset("CD")->find(4);
@@ -117,14 +117,11 @@
is( $cd->title, 'Greatest Hits 2: Louder Than Ever', 'find_or_new_related new record ok' );
ok( ! $cd->in_storage, 'find_or_new_related on a new record: not in_storage' );
-# print STDERR Data::Dumper::Dumper($cd->get_columns);
-# $cd->result_source->schema->storage->debug(1);
$cd->artist(undef);
my $newartist = $cd->find_or_new_related( 'artist', {
name => 'Random Boy Band Two',
artistid => 200,
} );
-# $cd->result_source->schema->storage->debug(0);
is($newartist->name, 'Random Boy Band Two', 'find_or_new_related new artist record with id');
is($newartist->id, 200, 'find_or_new_related new artist id set');
@@ -263,3 +260,12 @@
is ($@, '', 'Staged insertion successful');
ok($new_artist->in_storage, 'artist inserted');
ok($new_related_cd->in_storage, 'new_related_cd inserted');
+
+# check if is_foreign_key_constraint attr is set
+my $rs_normal = $schema->source('Track');
+my $relinfo = $rs_normal->relationship_info ('cd');
+cmp_ok($relinfo->{attrs}{is_foreign_key_constraint}, '==', 1, "is_foreign_key_constraint defined for belongs_to relationships.");
+
+my $rs_overridden = $schema->source('ForceForeign');
+my $relinfo_with_attr = $rs_overridden->relationship_info ('cd_3');
+cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for belongs_to relationships with attr.");
Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/ForceForeign.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/ForceForeign.pm 2008-11-10 23:04:43 UTC (rev 5096)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/ForceForeign.pm 2008-11-10 23:09:23 UTC (rev 5097)
@@ -29,4 +29,13 @@
},
);
+# Normally this would appear as a FK constraint
+__PACKAGE__->belongs_to(
+ 'cd_3', 'DBICTest::Schema::CD', {
+ 'foreign.cdid' => 'self.cd',
+ }, {
+ is_foreign_key_constraint => 0,
+ },
+);
+
1;
Modified: DBIx-Class/0.08/trunk/t/lib/sqlite.sql
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/sqlite.sql 2008-11-10 23:04:43 UTC (rev 5096)
+++ DBIx-Class/0.08/trunk/t/lib/sqlite.sql 2008-11-10 23:09:23 UTC (rev 5097)
@@ -1,6 +1,6 @@
--
-- Created by SQL::Translator::Producer::SQLite
--- Created on Sun Nov 9 16:28:17 2008
+-- Created on Mon Nov 10 23:52:55 2008
--
BEGIN TRANSACTION;
@@ -190,6 +190,7 @@
notes varchar(100) NOT NULL
);
+CREATE INDEX liner_notes_idx_liner_id_liner ON liner_notes (liner_id);
--
-- Table: link
More information about the Bast-commits
mailing list