Subject: | disable editability of primary keys in edit/create; support inflate_column defination |
Hi Oliver,
thank you the great catalyst plugin. Here two things i modified on your
version.
1. to disable editability of primary keys in edit/create form:
diff ~/perl5/lib/perl5/Catalyst/Plugin/AutoCRUD/Model/Metadata/DBIC.pm
~/Downloads/Catalyst-Plugin-AutoCRUD-1.110731/lib/Catalyst/Plugin/AutoCRUD/Model/Metadata/DBIC.pm
266c266
< editable => ($info->{is_auto_increment} ||
grep(/^$col$/, $source->primary_columns) ? 0 : 1),
---
Show quoted text
> editable => ($info->{is_auto_increment} ? 0 : 1),
275c275
< if (exists $info->{data_type} and exists $xtype_for{
lc($info->{data_type}) } and !$info->{_inflate_info});
---
Show quoted text> if (exists $info->{data_type} and exists $xtype_for{
lc($info->{data_type}) });
2. to enable in inflate_column defined source execution:
diff ~/perl5/lib/perl5/Catalyst/Plugin/AutoCRUD/Model/Backend/DBIC.pm
/home/alexei/Downloads/Catalyst-Plugin-AutoCRUD-1.110731/lib/Catalyst/Plugin/AutoCRUD/Model/Backend/DBIC.pm
226c226
< if (!defined eval{$row->$col}) {
---
Show quoted text> if (!defined eval{$row->get_column($col)}) {
231c231
< $data->{$col} = $row->$col;
---
Show quoted text> $data->{$col} = $row->get_column($col);
466a467,469
Show quoted text> $row = (( blessed $row )
> ? $row->set_columns( $data )
> : $c->model($model)->new_result( $data ) );
468,480d470
< $row = $c->model($model)->new({}) unless blessed $row;
<
< my $_data = {};
< foreach my $col(keys %{$data}) {
< if ($row->has_column($col) && exists
$row->column_info($col)->{_inflate_info}) {
< my $deflate =
$row->column_info($col)->{_inflate_info}->{deflate};
< $_data->{$col} = $deflate->($data->{$col}, $row);
< } else {
< $_data->{$col} = $data->{$col};
< }
< }
<
< $row = $row->set_columns( $_data );
483a474
Show quoted text>
for example a part of table defination:
"ip",
{ data_type => "INT", default_value => undef, is_nullable => 0, size
=> 10 },
__PACKAGE__->inflate_column(
'ip',
{
inflate => sub {
return Net::IP->new(inet_ntoa(pack("N", shift)))->ip;
},
deflate => sub {
return unpack("N", inet_aton(shift));
},
}
);
may be it can be helpful for some other one.
regards,
palik