Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove schema prefix in define_ methods as well #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/DBIx/DataModel/Meta/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ foreach my $kind (qw/table association type/) {

# store into our registry (except paths because they are accessed through
# tables or through associations)
$self->{$kind}{$meta_obj->{name}} = $meta_obj

my $name = $meta_obj->{name};
# remove schema prefix, if any
$name =~ s/^$self->{class}:://;

$self->{$kind}{$name} = $meta_obj
unless $kind eq 'path';

return $self;
Expand Down
28 changes: 22 additions & 6 deletions t/v2_define_class.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;

use Test::More tests => 1;
use Test::More tests => 10;

if (1 == 0) {
# the line below artificially populates DBIx::DataModel::Schema namespace
Expand All @@ -12,11 +12,27 @@ if (1 == 0) {

require DBIx::DataModel;

DBIx::DataModel->Schema('HR')
->Table(Employee => T_Employee => qw/emp_id/)
->Table(Department => T_Department => qw/dpt_id/)
->Table(Activity => T_Activity => qw/act_id/);

my $schema = DBIx::DataModel->Schema('HR');
$schema->Table(Employee => T_Employee => qw/emp_id/)
->Table(Department => T_Department => qw/dpt_id/)
->Table(Activity => T_Activity => qw/act_id/);

ok(scalar(keys %{HR::}), "class HR is defined");

# declaraton using short name
$schema->Table( 'Bar' => T_Bar => qw/id/);
ok(scalar(keys %{HR::Bar::}), "class HR::Bar is defined");
ok( $schema->table( 'Bar' ), 'Bar accessible via short name' );
ok( $schema->table( 'HR::Bar' ), 'HR::Bar accessible via full name' );

# declaraton using full name (within schema)
$schema->Table( 'HR::Foo' => T_Foo => qw/id/);
ok(scalar(keys %{HR::Foo::}), "class HR::Foo is defined");
ok( $schema->table( 'Foo' ), 'Foo accessible via short name' );
ok( $schema->table( 'HR::Foo' ), 'HR::Foo accessible via full name' );

# declaraton using full name (outside of schema)
$schema->Table( 'Space::Empty' => T_Empty => qw/id/);
ok(scalar(keys %{Space::Empty::}), "class Space::Empty is defined");
ok( !$schema->table( 'Empty' ), 'Empty is not accessible via short name' );
ok( $schema->table( 'Space::Empty' ), 'Space::Empty accessible via full name only' );