[html-formfu] Having issues with nested repeatable loading from db.

Leanan Sidhe the.leanan.sidhe at gmail.com
Thu Mar 5 16:59:14 GMT 2009


The only one that seems to be what I want is the
many_to_many_repeatable_nested tests.

I notice in there, the call to $form->model->default_values has an extra
parameter, a hash ref of { nested_base =3D> 'foo' }.

I tried adding {nested_base =3D> 'debits'} to mine, and the end result was
that now instead of at least getting all the data in my form from the
various might_haves, I get nothing.  The sql output also shows that it is
not querying all the related tables at the first level, as it does when I do
not have that hash ref.  If that is the way to do it, then I am lost for two
reasons:

1) I didn't even get at least my debits.debit_item.date, etc data loaded
from the database, and all the data I WAS getting now isn't being loaded.
2) I have a bunch of tables that have relationships like this one (for
instance, I have a credit and credititem table, with similar relationships
as the debit and debititem tables as set out below).  I need to load data
from all those as well.
3) I don't recall, in my reading of the docs, tests, mailing list archives
(I have skimmed all that are listed online, and read through anything that
seemed REMOTELY related to repeatables and loading from the db), nor been
able to google anything that even mentions this hash ref.  All I've been
able to come up with tells me that all I need to do is set up my schema, set
up the proper relationships, make sure my field name's match the column name
for the table I wish to load from, and make sure that my nested_names all
match the relationship names.  Which they do.

I'm at a loss here.  I do not come here asking for help without already
haveing tried everything I can as I understand it.  I have spent days trying
to figure out what I am doing wrong.

Is it my relationship type?  Should this be a many_to_many instead of a
has_many?  Basically, an account may or may not have any debits.  If they
do, there will be an entry in the debits table that has some basic
information about the whole set of debits, and then there may or may not be
a bunch of individual debits, each in the debititems table, that will list
information about the individual debit.  I know it doesn't quite make sense
to say in this example that you may have a row in the debits table without
any in the debititems table, but in my application (which is not dealing
with accounts, debits, etc) it makes sense.  I may_have a debit, and that
debit may have 0-x individual items associated with it.  This was the first
example I could come with that demonstrated something similar to my
situation, and I didn't want to use foo and bar because people tend to get
confused when you're using such nebulous terms.

On my form, I want to show the overall data for the set of debits, and then
display a table that lists all the individual debit items for that set of
debits.  This data is editable, so I need to load it all from the db.

Put it this way:  I am standing in front of a gorge, and I need to get
across.  I have the materials to make a bridge, but I do not know how to
make a bridge.  Everything that tells me how to make a bridge, when I try to
use it to make a bridge, ends up with a bridge that doesn't span the gorge.
I am missing some fine detail on bridge making that I need someone to point
out to me so that I can do it.  Telling me to look at all the instructions
again is not of any help, since I'm obviously having problems understanding
the instructions clearly enough to make said bridge.

On Thu, Mar 5, 2009 at 10:09 AM, Moritz Onken <onken at houseofdesign.de>wrote:

>
>
> Am 05.03.2009 um 15:40 schrieb Leanan Sidhe <the.leanan.sidhe at gmail.com>:
>
>
>
> On Thu, Mar 5, 2009 at 8:46 AM, Ascii King < <tech at swattermatter.com>
> tech at swattermatter.com> wrote:
>
>> For starters, I don't think it is supposed to be "schema =3D DB", just
>> "schema DB"
>>
>> <Controller::HTML::FormFu>
>>   <model_stash>
>>       schema DB
>>   </model_stash>
>> </Controller::HTML::FormFu>
>>
>> Also, could you show us the may_have line that sets up the 'debits'
>> relationship?
>
>
> I meant might_have, not may_have, and here it is:
> In MyApp::DB::Result::Account :
>
> __PACKAGE__->might_have(
>    'debits' =3D> 'MyApp::Schema::DB::Result::Debit',
>   'account_id'
> );
>
> Where both the Account and Debit Tables have an account_id field.  It's
> definitely walking this relationship, because my form is loading the
> "something" and "something_else" values.  It's just not going that extra
> step and loading all the related debit_items for that debit.  In case you
> are curious, that is set up like so:
>
> in MyApp::DB::Result::Debit :
>
> __PACKAGE__->has_many(
>   'debit_items' =3D> 'MyApp::Schema::DB::Result::DebitItems',
>   'debit_id'
> );
>
> Where both Debit and DebitItems table have a debit_id column.  This is
> where it breaks.  For my example, there is a row with debit_id 1 in Debit,
> and 3 rows in DebitItems with a debit_id of 1 that should match up.  Those
> three rows are not being loaded from the database.  It's not even giving =
me
> 3 empty rows.
>
> Should DB in my myapp.conf be DB::Result, instead, since all my table fil=
es
> are MyApp::Schema::DB::Result::xxx?  I've tried that, too, and it doesn't
> seem to make a difference.
>
> My controller has the following:
> sub testing :FormConfig('MyApp/myapp_base.yml') :PathPart('testing')
> Chained('/') Args(0) {
>   my ($self, $c) =3D @_;
>   my $form =3D $c->stash->{'form'};
>
>   if ($form->submitted_and_valid) {
>     $form->model->update([still trying to figure out what to put here but
> my first concern is getting loading working]);
>   } else {
>     $form->model->default_values($c->model('DB::Account')->find(1));
>   }
> }
>
> Obviously I'll make it a bit more dynamic later on, but this is just for
> testing purposes with some dummy data in the db.
>
> Please let me know if there's anything else I can tell you that would make
> it easier for you to figure out (except of course the original code, since
> that's proprietary)
>
> Thanks.
>
>
>
>
>
>>
>> Leanan Sidhe wrote:
>>
>>> I'm attempting to make use of the $form->model->default_values and
>>> $form->model->update methods.  Everything except for my repeatables are
>>> loading from the db, and I am at a loss as to why this is.  My guess is=
 that
>>> either 1) What I want to do cannot currently be done, or 2) I'm missing
>>> something simple, but important.  Here's an example of what I am trying=
 to
>>> do:
>>>
>>>
>>> I have something along the following for my tables:
>>>
>>> MyApp::DB::Result::Account:
>>>  - A may_have for MyApp::DB::Result::Debit, named debits
>>>
>>> MyApp::DB::Result::Debit
>>> - A belongs_to for MyApp::DB::Result::Account, named account
>>> - A has_many for MyApp::DB::Result::DebitItems, named debit_items
>>>
>>> MyApp::DB::Result::DebitItems
>>> - A belongs_to for MyApp::DB::Result::Debit, named debit
>>>
>>> myapp.conf has:
>>> name MyApp
>>> <Controller::HTML::FormFu>
>>>  <model_stash>
>>>    schema =3D DB
>>>  </model_stash>
>>> </Controller::HTML::FormFu>
>>>
>>> (I'm not sure if that is right.  I've tried MyApp::Model::DB, and
>>> MyApp::Schema::DB -- Model::DB lists the connection string, Schema::DB =
is
>>> the one with the load_namespaces)
>>>
>>> My form config has a base config file that loads a bunch of sub config
>>> files.  In one of the sub configs where I'm trying to get this working I
>>> have something like this:
>>>
>>> ---
>>>  elements:
>>>  nested_name: debits
>>>  elements:
>>>   - type: Block
>>>     tag: table
>>>        .... (lots of stuff building out the headers, etc.  Then I final=
ly
>>> get to the rows)
>>>   - type: Block
>>>     tag: tbody
>>>     elements:
>>>       - type: Repeatable
>>>       nested_name: debit_items
>>>       elements:
>>>         - type: Block
>>>           ... (lots of stuff building out the row I want repeated)
>>>
>>>
>>>
>>> When I load the form, I do
>>> $form->model->default_values($c->model('DB::Account')->find(1));
>>>
>>> The portion of the form that is not in the repeatable section loads fin=
e.
>>>  I'll have things like debits.something, debits.soemthing_else (where I=
 have
>>> something and something_else columns in the debit table)  All the data =
for
>>> those fields loads from the database just fine.
>>> The form builds out a table with one empty row, where the names are
>>> debits.debit_item.value, debits.debit_item.date, etc etc (where I have =
value
>>> and date columns in the debititems table).  However, the fields aren't
>>> populated from the database.
>>>
>>> As far as I can tell I've got everything right, but obviously I don't
>>> because it just doesn't work.  Is this possible, or am I dreaming?  If =
it's
>>> possible, what am I messing up?
>>>
>>> Thank you!
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> HTML-FormFu mailing list
>>>  <HTML-FormFu at lists.scsys.co.uk>HTML-FormFu at lists.scsys.co.uk
>>>  <http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu>
>>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>>
>>
>> _______________________________________________
>> HTML-FormFu mailing list
>>  <HTML-FormFu at lists.scsys.co.uk>HTML-FormFu at lists.scsys.co.uk
>>  <http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu>
>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
>
>
> You could write a test. Have a look at the formfu model dbic test suite.
> This will help you. There are already many defined which you can use.
>
> If I recall correctly I had this problem too.
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090305/64=
07280f/attachment.htm


More information about the HTML-FormFu mailing list