| 1 | package AutoSQL::TableModel; | ||
| 2 | use strict; | ||
| 3 | use AutoCode::ModuleModel; | ||
| 4 | our @ISA=qw(AutoCode::ModuleModel); | ||
| 5 | use AutoCode::AccessorMaker( | ||
| 6 | '$'=>[qw(table_name primary_key_name slots fk_slots)]); | ||
| 7 | |||
| 8 | sub _initialize { | ||
| 9 | my ($self, @args)=@_; | ||
| 10 | $self->SUPER::_initialize(@args); | ||
| 11 | |||
| 12 | $self->table_name(lc $self->type); | ||
| 13 | $self->primary_key_name($self->table_name .'_id'); | ||
| 14 | |||
| 15 | my %module=%{$self->schema->_get_module_definition($self->type)}; | ||
| 16 | my @subs = grep /^[_a-zA-Z]/, keys %module; | ||
| 17 | # my %v_attrs=%{$self->value_attribute}; | ||
| 18 | |||
| 19 | |||
| 20 | # my @slots = grep { my ($context, $kind)=($self->_classify_value_attribute($_))[0, 1]; | ||
| 21 | # $kind =~/^[PM]$/; }keys %v_attrs; | ||
| 22 | # $module{$_} =~ /^\$/} @{$self->value_attribute}; | ||
| 23 | |||
| 24 | # my @fk_slots = grep { ($self->_classify_value_attribute($_))[1] eq 'M'; | ||
| 25 | # }keys %v_attrs; | ||
| 26 | |||
| 27 | # $module{$_} =~ /^[@%$](\.+)/} @subs; | ||
| 28 | my @slots=grep{ | ||
| 29 | my ($context, $kind)=($self->_classify_value_attribute($_))[0, 1]; | ||
| 30 | $context eq'$' and $kind =~/^[PE]$/; | ||
| 31 | }$self->get_scalar_attributes; | ||
| 32 | my @scalar_children=grep{ | ||
| 33 | my ($context, $kind)=($self->_classify_value_attribute($_))[0, 1]; | ||
| 34 | $kind eq 'M'; | ||
| 35 | }$self->get_scalar_attributes; | ||
| 36 | my @array_children=grep{ | ||
| 37 | my ($context, $kind)=($self->_classify_value_attribute($_))[0, 1]; | ||
| 38 | $kind eq'M'; | ||
| 39 | }$self->get_array_attributes; | ||
| 40 | my $type=$self->type; | ||
| 41 | # print STDERR "Type $type 's children: scalar(@scalar_children), array(@array_children)\n"; | ||
| 42 | $self->slots(\@slots); | ||
| 43 | |||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | # figure out the table schema that was originally in schema, but now trying to | ||
| 48 | # be replaced by this.. | ||
| 49 | # | ||
| 50 | # | ||
| 51 | 1; |