delete $type_info->{artistid}{size};
delete $type_info->{name}{size};
-delete $type_info->{agent}{size};
my $test_type_info = {
'artistid' => {
'data_type' => 'varchar',
'is_nullable' => 0,
},
- 'agent' => {
- 'data_type' => 'integer',
- 'is_nullable' => 0,
- },
};
is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
plan tests => 8;
-my $label = $schema->resultset('Label')->find({ labelid => 1 });
+my $artist = $schema->resultset('Artist')->find(1);
# Check that you can leave off the alias
{
- my $existing_agent = $label->agents->find_or_create({
- name => 'Ted',
+ my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+ title => 'Ted',
+ year => 2006,
});
- ok(! $existing_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
- is($existing_agent->name, 'Ted', 'find_or_create on prefetched has_many with same column names: name matches existing entry');
+ ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+ is($existing_cd->title, 'Ted', 'find_or_create on prefetched has_many with same column names: name matches existing entry');
- my $new_agent = $label->agents->find_or_create({
- name => 'Someone Else',
+ my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+ title => 'Something Else',
+ year => 2006,
});
- ok(! $new_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
- is($new_agent->name, 'Someone Else', 'find_or_create on prefetched has_many with same column names: name matches');
+ ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+ is($new_cd->title, 'Something Else', 'find_or_create on prefetched has_many with same column names: title matches');
}
# Check that you can specify the alias
{
- my $existing_agent = $label->agents->find_or_create({
- 'me.name' => 'Someone Else',
+ my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+ 'me.title' => 'Something Else',
+ 'me.year' => 2006,
});
- ok(! $existing_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
- is($existing_agent->name, 'Someone Else', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for existing entry');
+ ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+ is($existing_cd->title, 'Something Else', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for existing entry');
- my $new_agent = $label->agents->find_or_create({
- 'me.name' => 'Some New Guy',
+ my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
+ 'me.title' => 'Some New Guy',
+ 'me.year' => 2006,
});
- ok(! $new_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
- is($new_agent->name, 'Some New Guy', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for new entry');
+ ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
+ is($new_cd->title, 'Some New Guy', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for new entry');
}
my $self = shift;
my $schema = shift;
- $schema->populate('Label', [
- [ qw/labelid name/ ],
- [ 1, 'Acme Records' ],
- ]);
-
- $schema->populate('Agent', [
- [ qw/agentid label name/ ],
- [ 1, 1, 'Ted' ],
- ]);
-
$schema->populate('Artist', [
- [ qw/artistid agent name/ ],
- [ 1, 1, 'Caterwauler McCrae' ],
- [ 2, 1, 'Random Boy Band' ],
- [ 3, 1, 'We Are Goth' ],
+ [ qw/artistid name/ ],
+ [ 1, 'Caterwauler McCrae' ],
+ [ 2, 'Random Boy Band' ],
+ [ 3, 'We Are Goth' ],
]);
$schema->populate('CD', [
no warnings qw/qw/;
__PACKAGE__->load_classes(qw/
- Agent
Artist
Employee
CD
- Label
Link
Bookmark
#dummy
+++ /dev/null
-package # hide from PAUSE
- DBICTest::Schema::Agent;
-
-use base 'DBIx::Class::Core';
-
-__PACKAGE__->table('agent');
-__PACKAGE__->add_columns(
- 'agentid' => {
- data_type => 'integer',
- is_auto_increment => 1
- },
- 'label' => {
- data_type => 'integer',
- },
- 'name' => {
- data_type => 'varchar',
- size => 100,
- is_nullable => 1,
- },
-);
-__PACKAGE__->set_primary_key('agentid');
-
-__PACKAGE__->has_many( artists => 'DBICTest::Schema::Artist' );
-__PACKAGE__->belongs_to( label => 'DBICTest::Schema::Label' );
-
-1;
data_type => 'integer',
is_auto_increment => 1
},
- 'agent' => {
- data_type => 'integer',
- is_nullable => 1,
- },
'name' => {
data_type => 'varchar',
size => 100,
__PACKAGE__->mk_classdata('field_name_for', {
artistid => 'primary key',
- agent => 'agent',
name => 'artist name',
});
{ order_by => 'year' },
);
-__PACKAGE__->belongs_to( agent => 'DBICTest::Schema::Agent' );
-
__PACKAGE__->has_many( twokeys => 'DBICTest::Schema::TwoKeys' );
__PACKAGE__->has_many( onekeys => 'DBICTest::Schema::OneKey' );
+++ /dev/null
-package # hide from PAUSE
- DBICTest::Schema::Label;
-
-use base 'DBIx::Class::Core';
-
-__PACKAGE__->table('label');
-__PACKAGE__->add_columns(
- 'labelid' => {
- data_type => 'integer',
- is_auto_increment => 1
- },
- 'name' => {
- data_type => 'varchar',
- size => 100,
- is_nullable => 1,
- },
-);
-__PACKAGE__->set_primary_key('labelid');
-
-__PACKAGE__->has_many(
- agents => 'DBICTest::Schema::Agent',
- undef,
- { prefetch => 'artists' }
-);
-
-1;
--
-- Created by SQL::Translator::Producer::SQLite
--- Created on Fri Aug 4 19:03:21 2006
+-- Created on Tue Aug 8 01:53:20 2006
--
BEGIN TRANSACTION;
--
CREATE TABLE artist (
artistid INTEGER PRIMARY KEY NOT NULL,
- agent integer,
- name varchar(100)
-);
-
---
--- Table: label
---
-CREATE TABLE label (
- labelid INTEGER PRIMARY KEY NOT NULL,
name varchar(100)
);
);
--
--- Table: tags
---
-CREATE TABLE tags (
- tagid INTEGER PRIMARY KEY NOT NULL,
- cd integer NOT NULL,
- tag varchar(100) NOT NULL
-);
-
---
--- Table: agent
---
-CREATE TABLE agent (
- agentid INTEGER PRIMARY KEY NOT NULL,
- label integer NOT NULL,
- name varchar(100)
-);
-
---
-- Table: link
--
CREATE TABLE link (
);
--
+-- Table: tags
+--
+CREATE TABLE tags (
+ tagid INTEGER PRIMARY KEY NOT NULL,
+ cd integer NOT NULL,
+ tag varchar(100) NOT NULL
+);
+
+--
-- Table: treelike
--
CREATE TABLE treelike (