{
local $SIG{__WARN__} = sub {};
eval { $dbh->do("DROP TABLE cd") };
- $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);");
+ $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER, single_track INTEGER);");
}
$schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 });
{
local $SIG{__WARN__} = sub {};
eval { $dbh->do("DROP TABLE cd") };
- $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);");
+ $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER, single_track INTEGER);");
}
$schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 });
{
local $SIG{__WARN__} = sub {};
eval { $dbh->do("DROP TABLE cd") };
- $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);");
+ $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER, single_track INTEGER);");
}
$schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 });
my $cd = $schema->resultset("CD")->find(1);
my %cols = $cd->get_columns;
-cmp_ok(keys %cols, '==', 5, 'get_columns number of columns ok');
+cmp_ok(keys %cols, '==', 6, 'get_columns number of columns ok');
is($cols{title}, 'Spoonful of bees', 'get_columns values ok');
# check whether ResultSource->columns returns columns in order originally supplied
my @cd = $schema->source("CD")->columns;
-is_deeply( \@cd, [qw/cdid artist title year genreid/], 'column order');
+is_deeply( \@cd, [qw/cdid artist title year genreid single_track/], 'column order');
$cd = $schema->resultset("CD")->search({ title => 'Spoonful of bees' }, { columns => ['title'] })->next;
is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');
# test remove_columns
{
- is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year genreid/]);
+ is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year genreid single_track/]);
$schema->source('CD')->remove_columns('year');
- is_deeply([$schema->source('CD')->columns], [qw/cdid artist title genreid/]);
+ is_deeply([$schema->source('CD')->columns], [qw/cdid artist title genreid single_track/]);
ok(! exists $schema->source('CD')->_columns->{'year'}, 'year still exists in _columns');
}
DROP TABLE cd");
$dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);");
-$dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT, title VARCHAR(100), year VARCHAR(100), genreid INT NULL);");
+$dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT, title VARCHAR(100), year VARCHAR(100), genreid INT NULL, single_track INT NULL);");
# Just to test compat shim, Auto is in Core
$schema->class('Artist')->load_components('PK::Auto::MSSQL');
my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
like(
$sql,
- qr/\QSELECT me.cdid, me.artist, me.title, me.year, me.genreid FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/,
+ qr/\QSELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/,
'got correct SQL with all bind parameters'
);
}
'genreid' => {
data_type => 'integer',
is_nullable => 1,
+ },
+ 'single_track' => {
+ data_type => 'integer',
+ is_nullable => 1,
+ is_foreign_key => 1,
}
);
__PACKAGE__->set_primary_key('cdid');
is_deferrable => 1,
});
+# in case this is a single-cd it promotes a track from another cd
+__PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track' );
+
__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' );
__PACKAGE__->has_many(
tags => 'DBICTest::Schema::Tag', undef,
__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD' );
__PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd');
+__PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' );
+
1;
--
-- Created by SQL::Translator::Producer::SQLite
--- Created on Mon Nov 10 23:52:55 2008
+-- Created on Sun Nov 16 10:43:11 2008
--
BEGIN TRANSACTION;
artist integer NOT NULL,
title varchar(100) NOT NULL,
year varchar(100) NOT NULL,
- genreid integer
+ genreid integer,
+ single_track integer
);
CREATE INDEX cd_idx_artist_cd ON cd (artist);
CREATE INDEX cd_idx_genreid_cd ON cd (genreid);
+CREATE INDEX cd_idx_single_track_cd ON cd (single_track);
CREATE UNIQUE INDEX cd_artist_title_cd ON cd (artist, title);
--