comparison Lib/IMPL/ORM/Object.pm @ 44:32d2350fccf9

ORM *Minor fixes *Working tarnsform to sql *Fixes to the sql traits
author Sergey
date Mon, 11 Jan 2010 01:42:00 +0300
parents d660fb38b7cc
children 16ada169ca75
comparison
equal deleted inserted replaced
43:009aa9ca2e48 44:32d2350fccf9
13 require IMPL::ORM::Schema::Relation::HasOne; 13 require IMPL::ORM::Schema::Relation::HasOne;
14 require IMPL::ORM::Schema::Relation::Subclass; 14 require IMPL::ORM::Schema::Relation::Subclass;
15 15
16 BEGIN { 16 BEGIN {
17 private _direct property _entities => prop_all; 17 private _direct property _entities => prop_all;
18 public property objectType => prop_all; 18 public property objectType => prop_all, {type => 'String'};
19
20 sub _PropertyImplementor {
21 'IMPL::ORM::PropertyImplementor'
22 }
19 } 23 }
20 24
21 my %schemaCache; 25 my %schemaCache;
22 26
23 sub CTOR { 27 sub CTOR {
40 my ($this,$class,$prop,$value) = @_; 44 my ($this,$class,$prop,$value) = @_;
41 45
42 return $this->{$_entities}{$class} ? $this->{$_entities}{$class}->Get($prop,$value) : undef; 46 return $this->{$_entities}{$class} ? $this->{$_entities}{$class}->Get($prop,$value) : undef;
43 } 47 }
44 48
45 sub _PropertyImplementor {
46 'IMPL::ORM::PropertyImplementor'
47 }
48
49 sub entityName { 49 sub entityName {
50 (my $self = ref $_[0] || $_[0]) =~ s/::/_/g; 50 (my $self = ref $_[0] || $_[0]) =~ s/^.*?(\w+)$/$1/;
51 return $self; 51 return $self;
52 } 52 }
53 53
54 sub ormGetSchema { 54 sub ormGetSchema {
55 my ($self,$dataSchema,$surrogate) = @_; 55 my ($self,$dataSchema,$surrogate) = @_;
68 ){ 68 ){
69 if ($ormProp->Mutators & prop_list) { 69 if ($ormProp->Mutators & prop_list) {
70 # отношение 1 ко многим 70 # отношение 1 ко многим
71 my $type = $dataSchema->resolveType($ormProp->Type) or die new IMPL::InvalidOperationException("Failed to resolve a reference type due building schema for a class", $ormProp->Class, $ormProp->Name); 71 my $type = $dataSchema->resolveType($ormProp->Type) or die new IMPL::InvalidOperationException("Failed to resolve a reference type due building schema for a class", $ormProp->Class, $ormProp->Name);
72 $schema->appendChild( new IMPL::ORM::Schema::Relation::HasMany($ormProp->Name, $type->entityName) ); 72 $schema->appendChild( new IMPL::ORM::Schema::Relation::HasMany($ormProp->Name, $type->entityName) );
73 } elsif (my $type = $dataSchema->isValueType($ormProp->Type,'IMPL::ORM::Object')) { 73 } elsif (my $type = $dataSchema->isValueType($ormProp->Type)) {
74 # поле 74 # поле
75 $schema->appendChild( new IMPL::ORM::Schema::Field($ormProp->Name,$type->name) ); 75 $schema->appendChild( new IMPL::ORM::Schema::Field($ormProp->Name,$ormProp->Type) );
76 } elsif (my $entity = $dataSchema->resolveType($ormProp->Type)) { 76 } elsif (my $entity = $dataSchema->resolveType($ormProp->Type)) {
77 # отношение ссылка 77 # отношение ссылка
78 $schema->appendChild( new IMPL::ORM::Schema::Relation::HasOne($ormProp->Name,$entity->entityName)); 78 $schema->appendChild( new IMPL::ORM::Schema::Relation::HasOne($ormProp->Name,$entity->entityName));
79 } else { 79 } else {
80 # хз что. Скорее всего не удалось квалифицировать тип свойства не как ссылочный и как поле. 80 # хз что. Скорее всего не удалось квалифицировать тип свойства не как ссылочный и как поле.