r35572 - in /trunk/libhtml-formfu-model-dbic-perl: Changes META.yml Makefile.PL debian/changelog debian/patches/fix-pod-errors.patch debian/patches/how-to-report-bugs.diff lib/HTML/FormFu/Model/DBIC.pm t/lib/DBICTestLib.pm t/lib/MySchema/User.pm

ansgar-guest at users.alioth.debian.org ansgar-guest at users.alioth.debian.org
Sun May 17 14:30:55 UTC 2009


Author: ansgar-guest
Date: Sun May 17 14:30:50 2009
New Revision: 35572

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=35572
Log:
New upstream release.

Modified:
    trunk/libhtml-formfu-model-dbic-perl/Changes
    trunk/libhtml-formfu-model-dbic-perl/META.yml
    trunk/libhtml-formfu-model-dbic-perl/Makefile.PL
    trunk/libhtml-formfu-model-dbic-perl/debian/changelog
    trunk/libhtml-formfu-model-dbic-perl/debian/patches/fix-pod-errors.patch
    trunk/libhtml-formfu-model-dbic-perl/debian/patches/how-to-report-bugs.diff
    trunk/libhtml-formfu-model-dbic-perl/lib/HTML/FormFu/Model/DBIC.pm
    trunk/libhtml-formfu-model-dbic-perl/t/lib/DBICTestLib.pm
    trunk/libhtml-formfu-model-dbic-perl/t/lib/MySchema/User.pm

Modified: trunk/libhtml-formfu-model-dbic-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/Changes?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/Changes (original)
+++ trunk/libhtml-formfu-model-dbic-perl/Changes Sun May 17 14:30:50 2009
@@ -1,4 +1,8 @@
-0.04002 2009-04-22
+0.04003 2009-05-10
+
+    - Bumped prerequisite HTML-FormFu to 0.04002
+
+0.04002 2009-05-08
 
     - New "empty_rows" setting - replaces now deprecated "new_empty_row".
     

Modified: trunk/libhtml-formfu-model-dbic-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/META.yml?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/META.yml (original)
+++ trunk/libhtml-formfu-model-dbic-perl/META.yml Sun May 17 14:30:50 2009
@@ -23,10 +23,10 @@
   DBD::SQLite: 0
   DBIx::Class: 0.08002
   DateTime::Format::MySQL: 0
-  HTML::FormFu: 0.03007
+  HTML::FormFu: 0.04002
   List::MoreUtils: 0
   Task::Weaken: 0
   perl: 5.8.1
 resources:
   license: http://dev.perl.org/licenses/
-version: 0.04002
+version: 0.04003

Modified: trunk/libhtml-formfu-model-dbic-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/Makefile.PL?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/Makefile.PL (original)
+++ trunk/libhtml-formfu-model-dbic-perl/Makefile.PL Sun May 17 14:30:50 2009
@@ -7,7 +7,7 @@
 requires 'DateTime::Format::MySQL';
 requires 'DBD::SQLite';
 requires 'DBIx::Class' => '0.08002';
-requires 'HTML::FormFu' => '0.03007';
+requires 'HTML::FormFu' => '0.04002';
 requires 'List::MoreUtils';
 requires 'Task::Weaken'; # to ensure Scalar::Util was built with weaken()
 

Modified: trunk/libhtml-formfu-model-dbic-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/debian/changelog?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/debian/changelog (original)
+++ trunk/libhtml-formfu-model-dbic-perl/debian/changelog Sun May 17 14:30:50 2009
@@ -1,3 +1,9 @@
+libhtml-formfu-model-dbic-perl (0.04003-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Ansgar Burchardt <ansgar at 43-1.org>  Sun, 17 May 2009 16:30:28 +0200
+
 libhtml-formfu-model-dbic-perl (0.04002-1) unstable; urgency=low
 
   [ Ansgar Burchardt ]

Modified: trunk/libhtml-formfu-model-dbic-perl/debian/patches/fix-pod-errors.patch
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/debian/patches/fix-pod-errors.patch?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/debian/patches/fix-pod-errors.patch (original)
+++ trunk/libhtml-formfu-model-dbic-perl/debian/patches/fix-pod-errors.patch Sun May 17 14:30:50 2009
@@ -4,7 +4,7 @@
 
 --- libhtml-formfu-model-dbic-perl.orig/lib/HTML/FormFu/Model/DBIC.pm
 +++ libhtml-formfu-model-dbic-perl/lib/HTML/FormFu/Model/DBIC.pm
-@@ -1283,6 +1283,8 @@
+@@ -1344,6 +1344,8 @@
  The field's L<name|HTML::FormFu::Element::_Field/name> must be set to the 
  name of the C<many_to_many> relationship.
  
@@ -13,7 +13,7 @@
  =item default_column
  
  If you want to search / associate the related table by a column other it's
-@@ -1295,6 +1297,7 @@
+@@ -1356,6 +1358,7 @@
            model_config:
              default_column: foo
  

Modified: trunk/libhtml-formfu-model-dbic-perl/debian/patches/how-to-report-bugs.diff
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/debian/patches/how-to-report-bugs.diff?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/debian/patches/how-to-report-bugs.diff (original)
+++ trunk/libhtml-formfu-model-dbic-perl/debian/patches/how-to-report-bugs.diff Sun May 17 14:30:50 2009
@@ -3,7 +3,7 @@
 
 --- libhtml-formfu-model-dbic-perl.orig/lib/HTML/FormFu/Model/DBIC.pm
 +++ libhtml-formfu-model-dbic-perl/lib/HTML/FormFu/Model/DBIC.pm
-@@ -1592,9 +1592,13 @@
+@@ -1653,9 +1653,13 @@
  
  =head1 BUGS
  

Modified: trunk/libhtml-formfu-model-dbic-perl/lib/HTML/FormFu/Model/DBIC.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/lib/HTML/FormFu/Model/DBIC.pm?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/lib/HTML/FormFu/Model/DBIC.pm (original)
+++ trunk/libhtml-formfu-model-dbic-perl/lib/HTML/FormFu/Model/DBIC.pm Sun May 17 14:30:50 2009
@@ -9,7 +9,7 @@
 use Storable qw( dclone );
 use Carp qw( croak );
 
-our $VERSION = '0.04002';
+our $VERSION = '0.04003';
 $VERSION = eval $VERSION;
 
 # sub _compatible_config() is only required as long as we support deprecated
@@ -214,13 +214,18 @@
                     || $dbic->$name->result_source->primary_columns;
 
                 my $info = $dbic->result_source->relationship_info($name);
+
                 if ( !defined $info or $info->{attrs}{accessor} eq 'multi' ) {
                     my @defaults = $dbic->$name->get_column($col)->all;
                     $field->default( \@defaults );
                 }
+                else {
+                    # has_one/might_have
+                    my($pk) = $dbic->result_source->primary_columns;
+                    $field->default( $dbic->$name->$pk );
+                }
             }
             else {
-
                 # This field is a method expected to return the value
                 $field->default( $dbic->$name );
             }
@@ -442,29 +447,29 @@
     return if $attrs->{no_follow};
 
     for my $rel (@$rels) {
-
         # don't follow rels to where we came from
         next
             if defined $attrs->{from}
                 && $attrs->{from} eq $rs->related_source($rel)->result_class;
-
-        my ($block)
-            = grep { !$_->is_field }
-            @{ $base->get_all_elements( { nested_name => $rel } ) };
-
-        next if !defined $block;
+        
+        my @elements = @{ $base->get_all_elements( { nested_name => $rel } ) };
+        
+        my ($block)       = grep { !$_->is_field } @elements;
+        my ($multi_value) = grep { $_->is_field && $_->multi_value } @elements;
+
+        next if !defined $block && !defined $multi_value;
         next if !$form->valid($rel);
 
         my $params = $form->param($rel);
 
-        if ( $block->is_repeatable ) {
+        if ( defined $block && $block->is_repeatable ) {
 
             # Handle has_many
 
             _save_has_many( $self, $dbic, $form, $rs, $block, $rel, $attrs );
 
         }
-        elsif ( ref $params eq 'HASH' ) {
+        elsif ( defined $block && ref $params eq 'HASH' ) {
             my $target = $dbic->find_related( $rel, {} );
 
             if ( !defined $target && grep { length $_ } values %$params ) {
@@ -480,6 +485,42 @@
                     nested_base => $rel,
                     from        => $dbic->result_class,
                 } );
+        }
+        elsif ( defined $multi_value ) {
+            # has_one or might_have relationship
+                        
+            my $info = $dbic->result_source->relationship_info($rel);
+            
+            my @fpkey = $dbic->related_resultset($rel)->result_source->primary_columns;
+            
+            croak 'multiple primary keys are not supported for has_one/might_have relationships'
+              if(@fpkey > 1);
+            
+            my $fpkey = shift @fpkey;
+            my ( $fkey, $skey ) = %{ $info->{cond} };
+            $fkey =~ s/^foreign\.//;
+            $skey =~ s/^self\.//;
+            
+            my $fclass = $info->{class};
+            
+            croak 'The primary key and the foreign key may not be the same column in class '.$fclass
+              if $fpkey eq $fkey;
+              
+            my $schema = $dbic->result_source->schema;
+            
+            # use transactions if supported by storage
+            $schema->txn_do(sub {
+
+                # reset any previous items which were related to $dbic        
+                $rs->schema->resultset($fclass)->search({ $fkey => $dbic->$skey })->update({ $fkey => undef });
+            
+                # set new related item
+                my $updated = $rs->schema->resultset($fclass)->search( { $fpkey => $params } )->update({ $fkey => $dbic->$skey });
+            
+                $schema->txn_rollback
+                  if $updated != 1;
+                  
+            });
         }
     }
 }
@@ -744,7 +785,9 @@
         {
             $dbic->set_column( $accessor, $value );
         }
-        elsif ( $dbic->can($accessor) ) {
+        elsif ( $dbic->can($accessor) 
+            # and $accessor is not a has_one or might_have rel where the foreign key is on the foreign table
+            and !$dbic->result_source->relationship_info($accessor)) {
             $dbic->$accessor($value);
         }
         else {
@@ -1164,7 +1207,8 @@
     __PACKAGE__->table("review");
     
     __PACKAGE__->add_columns(
-        book        => { data_type => "INTEGER" },
+        id          => { data_type => "INTEGER" },
+        book        => { data_type => "INTEGER", is_nullable => 1 },
         review_text => { data_type => "TEXT" },
     );
     
@@ -1189,6 +1233,23 @@
 For C<might_have> and C<has_one> relationships, you generally shouldn't need
 to have a field for the related table's primary key, as DBIx::Class will
 handle retrieving the correct row automatically.
+
+You can also set a C<has_one> or C<might_have> relationship using a multi value
+field like L<Select|HTML::FormFu::Element::Select>. 
+
+    elements:
+      - type: Text
+        name: title
+      
+      - type: Select
+        nested: review
+        model_config:
+          resultset: Review
+
+This will load all reviews into the select field. If you select a review from
+that list, a current relationship to a review is removed and the new one is 
+added. This requires that the primary key of the C<Review> table and the 
+foreign key do not match.
 
 =head2 has_many and many_to_many relationships
 

Modified: trunk/libhtml-formfu-model-dbic-perl/t/lib/DBICTestLib.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/t/lib/DBICTestLib.pm?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/t/lib/DBICTestLib.pm (original)
+++ trunk/libhtml-formfu-model-dbic-perl/t/lib/DBICTestLib.pm Sun May 17 14:30:50 2009
@@ -75,7 +75,7 @@
     $dbh->do( <<SQL );
 CREATE TABLE user (
   id     INTEGER PRIMARY KEY NOT NULL,
-  master INTEGER NOT NULL,
+  master INTEGER,
   name   TEXT NOT NULL,
   title  TEXT
 );

Modified: trunk/libhtml-formfu-model-dbic-perl/t/lib/MySchema/User.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-formfu-model-dbic-perl/t/lib/MySchema/User.pm?rev=35572&op=diff
==============================================================================
--- trunk/libhtml-formfu-model-dbic-perl/t/lib/MySchema/User.pm (original)
+++ trunk/libhtml-formfu-model-dbic-perl/t/lib/MySchema/User.pm Sun May 17 14:30:50 2009
@@ -10,7 +10,7 @@
 
 __PACKAGE__->add_columns(
     id     => { data_type => "INTEGER", is_nullable => 0 },
-    master => { data_type => "INTEGER", is_nullable => 0 },
+    master => { data_type => "INTEGER", is_nullable => 1 },
     name   => { data_type => "TEXT", is_nullable => 0 },
     title  => { data_type => "TEXT" },
 );




More information about the Pkg-perl-cvs-commits mailing list