Skip Menu |

This queue is for tickets about the Catalyst-Plugin-AutoCRUD CPAN distribution.

Report information
The Basics
Id: 68143
Status: rejected
Priority: 0/
Queue: Catalyst-Plugin-AutoCRUD

People
Owner: OLIVER [...] cpan.org
Requestors: info [...] maximka.de
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.110731
Fixed in: (no value)



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
Hi Palik, Many thanks for the feedback and patches. On Thu May 12 08:08:55 2011, palik wrote: Show quoted text
> 1. to disable editability of primary keys in edit/create form:
I'm not sure this should be necessary - PK cols are configured not to be editable. Please, if this isn't working properly for you, could you send me a section of your DBIx::Class Schema so I can see the column's configuration? Show quoted text
> 2. to enable in inflate_column defined source execution:
Show quoted text
> __PACKAGE__->inflate_column( > 'ip', > { > inflate => sub { > return Net::IP->new(inet_ntoa(pack("N", shift)))->ip; > }, > deflate => sub { > return unpack("N", inet_aton(shift)); > }, > } > );
This is a good idea - I'll work on this patch and hope to get this feature into a future version. Thanks! I'll transfer this to a ticket on Github so that we can close this ticket. -- regards, oliver.
Hi Oliver, thank you for response. 1. to disable editability of primary keys Ich use DBIx::Class::Schema::Loader VERSION = 0.04006 DBIx::Class VERSION = 0.08115 is_auto_increment hasn't been set for PK See the code stub in attachment. Regards, Palik
Subject: Cmts.pm
package X::Schema::Cmts; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("cmts"); __PACKAGE__->add_columns( "id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 10 }, "name", { data_type => "VARCHAR", default_value => undef, is_nullable => 0, size => 50, }, "ip", { data_type => "INT", default_value => undef, is_nullable => 0, size => 10 }, "vendor", { data_type => "VARCHAR", default_value => undef, is_nullable => 0, size => 50, }, "model", { data_type => "VARCHAR", default_value => undef, is_nullable => 0, size => 50, }, "site", { data_type => "VARCHAR", default_value => undef, is_nullable => 0, size => 50, }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("cmts_name_idx", ["name"]); __PACKAGE__->has_many( "device_cmts", "X::Schema::DeviceCmts", { "foreign.cmts" => "self.id" }, ); # Created by DBIx::Class::Schema::Loader v0.04006 @ 2011-05-06 12:16:50 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hIWw7ACWgu6cYLRuHVPZ1g use Net::IP; use Socket qw/inet_aton inet_ntoa/; __PACKAGE__->inflate_column( 'ip', { inflate => sub { return Net::IP->new(inet_ntoa(pack("N", shift)))->ip; }, deflate => sub { return unpack("N", inet_aton(shift)); }, } ); 1;
Hi, Sorry for taking a long time to get back to you about this - I'm now working on AutoCRUD again. On Sat May 21 02:37:48 2011, palik wrote: Show quoted text
> 1. to disable editability of primary keys > Ich use > DBIx::Class::Schema::Loader VERSION = 0.04006 > DBIx::Class VERSION = 0.08115 > is_auto_increment hasn't been set for PK > See the code stub in attachment.
Okay, so I think AutoCRUD is behaving correctly. If you do *not* set is_auto_increment then there is no reason why the user cannot edit the primary key field. In fact for "new" records the user must enter the value because the database will not insert one from a sequence. And for "edit" it is also legitimate to change the primary key, I believe. The other issue you mentioned, about inflating columns, is now tracked on GitHub as an issue for the module to resolve, so I'll close this ticket. Many thanks for your feedback, I do really appreciate it :-) -- regards, oliver.