Am 05.03.2009 um 15:40 schrieb Leanan Sidhe <the.leanan.si...@gmail.com>:



On Thu, Mar 5, 2009 at 8:46 AM, Ascii King <t...@swattermatter.com> wrote: For starters, I don't think it is supposed to be "schema = 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' => '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' => '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 files 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) = @_;
  my $form = $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 = 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 finally 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 fine. 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@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@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@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to