28
|
1 package Test::ORM::Schema;
|
|
2 use strict;
|
|
3 use warnings;
|
30
|
4 use base qw(IMPL::Test::Unit);
|
28
|
5
|
30
|
6 __PACKAGE__->PassThroughArgs;
|
|
7
|
|
8 use IMPL::Test qw(test failed);
|
|
9
|
|
10 test ExtractClassSchema => sub {
|
|
11 my ($this) = @_;
|
|
12
|
|
13 my $schema = Test::ORM::Schema::Data::User->ormGetSchema('Test::ORM::Schema::Data');
|
|
14 failed "Wrong number of the elements","expected: 4","got: ".$schema->childNodes->Count unless $schema->childNodes->Count == 4;
|
|
15
|
|
16 return 1;
|
|
17 };
|
|
18
|
|
19 test StaticSchema => sub {
|
|
20 my ($this) = @_;
|
|
21
|
|
22 my $schema = Test::ORM::Schema::Data->instance;
|
|
23
|
|
24 return 1;
|
|
25 };
|
|
26
|
28
|
27
|
|
28 package Test::ORM::Schema::Data::User;
|
|
29 use base qw(IMPL::ORM::Object);
|
|
30 use IMPL::Class::Property;
|
|
31
|
|
32 BEGIN {
|
|
33 public property Name => prop_all, { type => 'String' }; # Field
|
|
34 public property Id => prop_all, { type => 'String' }; # Field
|
|
35 public property Roles => prop_all | prop_list, { type=> 'Test::ORM::Schema::Data::Role'}; # HasMany
|
|
36 }
|
|
37
|
|
38 package Test::ORM::Schema::Data::Role;
|
|
39 use base qw(IMPL::ORM::Object);
|
|
40 use IMPL::Class::Property;
|
|
41
|
|
42 BEGIN {
|
|
43 public property Name => prop_all, { type => 'String' }; # Field
|
|
44 }
|
|
45
|
|
46 package Test::ORM::Schema::Data::Session;
|
|
47 use base qw(IMPL::ORM::Object);
|
|
48 use IMPL::Class::Property;
|
|
49 use IMPL::ORM::Helpers qw(Map);
|
|
50
|
|
51 BEGIN {
|
|
52 public property Id => prop_get, { type => 'String' }; # Field
|
|
53 public property User => prop_get, { type => 'Test::ORM::Schema::Data::User' }; # HasOne
|
|
54 public property Data => prop_all, { type => Map( 'String','String' ) }; # HasOne
|
|
55 public property AccessTime => prop_get { type => 'DateTime' }; # Field
|
|
56 }
|
|
57
|
|
58 package Test::ORM::Schema::Data;
|
|
59 use base qw(IMPL::ORM::Schema);
|
|
60
|
|
61 __PACKAGE__->ValueTypes (
|
|
62 'String' => 'IMPL::ORM::Value::String',
|
|
63 'DateTime' => 'IMPL::ORM::Value::DateTime',
|
|
64 'Integer' => 'IMPL::ORM::Value::Inetger',
|
|
65 'Float' => 'IMPL::ORM::Value::Float',
|
|
66 'Decimal' => 'IMPL::ORM::Value::Decimal'
|
|
67 );
|
|
68
|
30
|
69 __PACKAGE__->usePrefix(__PACKAGE__);
|
|
70 __PACKAGE__->Classes qw(
|
|
71 User
|
|
72 Role
|
|
73 Session
|
|
74 );
|
|
75
|
28
|
76 1;
|