Mercurial > pub > Impl
comparison Lib/IMPL/ORM/Object.pm @ 29:37160f7c8edb
minor changes
author | Sergey |
---|---|
date | Wed, 21 Oct 2009 17:30:20 +0400 |
parents | 6d33f75c6e1f |
children | dd4d72600c69 |
comparison
equal
deleted
inserted
replaced
28:6d33f75c6e1f | 29:37160f7c8edb |
---|---|
54 sub ormGetSchema { | 54 sub ormGetSchema { |
55 my ($self,$dataSchema) = @_; | 55 my ($self,$dataSchema) = @_; |
56 | 56 |
57 my $schema = IMPL::ORM::Schema::Entity->new($self->entityName); | 57 my $schema = IMPL::ORM::Schema::Entity->new($self->entityName); |
58 | 58 |
59 # для текущего класса, проходим по всем свойствам | |
59 foreach my $ormProp ( | 60 foreach my $ormProp ( |
60 $self->get_meta( | 61 $self->get_meta( |
61 'IMPL::Class::PropertyInfo', | 62 'IMPL::Class::PropertyInfo', |
62 sub { | 63 sub { |
63 UNIVERSAL::isa($_->Implementor, 'IMPL::ORM::Property' ) | 64 UNIVERSAL::isa($_->Implementor, 'IMPL::ORM::Property' ) |
64 }, | 65 }, |
65 0 | 66 0 |
66 ) | 67 ) |
67 ){ | 68 ){ |
68 if ($ormProp->Mutators & prop_list) { | 69 if ($ormProp->Mutators & prop_list) { |
70 # отношение 1 ко многим | |
69 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); |
70 $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) ); |
71 } elsif (my $type = $dataSchema->isValueType($ormProp->Type,'IMPL::ORM::Object')) { | 73 } elsif (my $type = $dataSchema->isValueType($ormProp->Type,'IMPL::ORM::Object')) { |
74 # поле | |
72 $schema->appendChild( new IMPL::ORM::Schema::Field($ormProp->Name,$type) ); | 75 $schema->appendChild( new IMPL::ORM::Schema::Field($ormProp->Name,$type) ); |
73 } elsif (my $entity = $dataSchema->resolveType($ormProp->Type)) { | 76 } elsif (my $entity = $dataSchema->resolveType($ormProp->Type)) { |
77 # отношение ссылка | |
74 $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)); |
75 } else { | 79 } else { |
80 # хз что. Скорее всего не удалось квалифицировать тип свойства не как ссылочный и как поле. | |
76 die new IMPL::Exception('Uexpected error due building schema for a class', $ormProp->Class, $ormProp->Name); | 81 die new IMPL::Exception('Uexpected error due building schema for a class', $ormProp->Class, $ormProp->Name); |
82 } | |
83 } | |
84 | |
85 # Формируем отношения наследования | |
86 { | |
87 # локализуем прагму | |
88 no strict 'refs'; | |
89 | |
90 my $class = ref $self || $self; | |
91 | |
92 # по всем классам | |
93 foreach my $super (grep $_->isa(__PACKAGE__), @{"${class}::ISA"}) { | |
94 my $type = $dataSchema->resolveType($super) or die new IMPL::InvalidOperationException("Failed to resolve a super class due building schema for a class", $class, $super); | |
95 $schema->appentChild(new IMPL::ORM::Schema::Relation::Subclass($type)); | |
77 } | 96 } |
78 } | 97 } |
79 | 98 |
80 return $schema; | 99 return $schema; |
81 } | 100 } |