baergaj // pullingshots // andrew@pullingshots.ca

DBIx in IC5

Andrew Baerg // Perl Dancer 2015

My::Schema::Result::Userdb

__PACKAGE__->has_many(
    transactions => 'My::Schema::Result::Transaction', 'username'
);

My::Schema::Result::Transaction

__PACKAGE__->belongs_to(
    customer => 'My::Schema::Result::Userdb', 'username', 
    { 'is_foreign_key_constraint' => 0, }, 
);

My::Schema::ResultSet::Transaction;

sub complete {
  my ($self) = @_;
  
  return $self->search(
    {
      'me.status' => { '-in' => ['shipped','imported','complete'] },
      'me.deleted' => { '!=' => 1 },
    }, {},
  );
}
Sub <<EOG
sub get_schema{
 # get the database handle
  my $db;
  $db = $Db{parts} or do {
    $Tag->perl({ table => 'parts'});
    $db = $Db{parts} or die "Table parts is not available";
  };
  my $dbh = $db->dbh()
    or die "not a DBI table";

  return My::Schema->connect( sub { $dbh }, '');
}
EOG
catalog.cfg

UserTag foreach Alias loop

diff --git a/lib/Vend/Interpolate.pm b/lib/Vend/Interpolate.pm
index c02f6f1..0b59a9f 100644
--- a/lib/Vend/Interpolate.pm
+++ b/lib/Vend/Interpolate.pm
@@ -4793,10 +4793,22 @@ sub tag_loop_list {
        ## about passing embedded Perl objects to a list
 
        # Can pass object.mv_results=$ary object.mv_field_names=$ary
+  if ($opt->{arrayref}) {
+    $opt->{object}->{mv_results} = $opt->{arrayref};
+  }
        if ($opt->{object}) {
                my $obj = $opt->{object};
                # ensure that number of matches is always set
                # so [on-match] / [no-match] works
+    if (ref($obj->{mv_results}) ne 'ARRAY') {
+                       logError("loop was not passed an arrayref in object.mv_results=`...` argument. Got " . $obj->{m
+                       return;
+    }
+    return unless scalar @{$obj->{mv_results}} > 0;
+    if (ref($obj->{mv_results}->[0]) ne 'HASH') {
+                       logError("loop was not passed an arrayref of hashrefs in object.mv_results=`...` argument. Got 
+                       return;
+    }
                $obj->{matches} = scalar(@{$obj->{mv_results}});
                return region($opt, $text);
        }
UserTag/ActionMap:

$Scratch->{orders} = [
  $Sub->get_schema()
    ->resultset('Userdb')
      ->find('ABT3K')
        ->transactions
          ->complete
            ->hri
];

OR

$Scratch->{orders} = My::Orders->new(
  schema => $Sub->get_schema(),
  customer => 'ABT3K',
  pending => 1,
)->list;


Page:

<ul>
[foreach arrayref=`$Scratch->{orders}` prefix="order"]

<li>[order-param order_number]: [order-param order_date]</li>

[/foreach]
</ul>
in UserTag:
  
my $customer = $Sub->get_schema()
                    ->resultset('Userdb')
                       ->find('ABT3K');
if ($customer) {
    $Scratch->{orders} = [
      $customer->transactions
                  ->complete
                    ->hri
    ];
}

in Schema::Result::

__PACKAGE__->has_many(
    customers => 'Edge::Company::Schema::Result::Userdb',
    { 'foreign.email' => 'self.email' },
    { cascade_copy => 0, cascade_delete => 0 },
);

baergaj // pullingshots // andrew@pullingshots.ca

Thank you!

Andrew Baerg // Perl Dancer 2015

DBIx in IC5

By baergaj

DBIx in IC5

Perl Dancer 2015

  • 357
Loading comments...

More from baergaj