[Catalyst] Relations 1:M

neila neila at post.pl
Tue Apr 28 18:02:49 GMT 2009


Welcome,

I have got a problem with relation has_many.
I have got 2 tables:

CREATE TABLE podmioty (
lpp integer not null primary key autoincrement,
nazwa varchar(100),
nip varchar(20),
regon varchar(20),
adres varchar(100),
osoba varchar(50),
uwagi varchar(200)
);

sqlite> .schema umowy
CREATE TABLE umowy (
lpu integer not null primary key autoincrement,
nrumowy varchar(50),
datazawarcia date,
datakonca date,
dane varchar(100),
opis varchar(100),
uwagi varchar(200),
podmiot integer references podmioty(lpp),
powiazanie integer default 0
);


podmiot has many umowy. I use FormFu this way:
1 ---
2 languages: ['pl']
3 indicator: submit
4 auto_fieldset: { legend: 'Lista umów' }
5
6 elements:
7
8 - type: Text
9 name: nrumowy
10 label: Nr umowy
11 container_attributes:
12 title: Nr umowy
13 constraints:
14 - Required
15
16 - type: Block
17 content_xml: "<br />"
18
19 - type: Date
20 name: datazawarcia
21 label: Data zawarcia
22 day:
23 prefix: " - Dzień - "
24 month:
25 prefix: " - Miesiąc - "
26 year:
27 prefix: " - Rok - "
28 less: 20
29 plus: 20
30 auto_inflate: 1
31 container_attributes:
32 title: Data zawarcia
33
34 - type: Block
35 content_xml: "<br />"
36
37 - type: Date
38 name: datakonca
39 label: Data końca
40 day:
41 prefix: " - Dzień - "
42 month:
43 prefix: " - Miesiąc - "
44 year:
45 prefix: " - Rok - "
46 less: 20
47 plus: 20
48 auto_inflate: 1
49 container_attributes:
50 title: Data końca
51
52 - type: Text
53 name: dane
54 label: Dane
55 container_attributes:
56 title: Dane
57
58 - type: Text
59 name: opis
60 label: Opis
61 container_attributes:
62 title: Opis
63
64 - type: Text
65 name: uwagi
66 label: Uwagi
67 container_attributes:
68 title: Uwagi
69
70 - type: Block
71 content_xml: "<br />"
72
73 # - type: Select
74 # name: podmioty
75 # label: Podmioty
76 # model_config:
77 # resultset: TableClass
78 # - type: Repeatable
79 # nested_name: podmioty
80 # model_config:
81 # new_empty_row: podmiot
82 # elements:
83 # - type: Hidden
84 # name: lpp
85 # - type: Text
86 # name: nazwa
87
88 - type: Select
89 name: podmioty
90 label: Podmioty
91 model_config:
92 model: 'hubeDB::Podmioty'
93 resultset: 'hubeDB::Umowy'
94 id_column: lpp
95
96 - type: Submit
97 name: submit
98 value: Zapisz
99
100 - type: Submit
101 name: cancel
102 value: Anuluj

When I run edit umowy I have got good form with select from podmioty ( 
with lpp in values and name in select ) :

<select name="podmioty">
<option value="3">HERBI</option>
<option value="4">Asseco</option>
<option value="8">LiNiO Company</option>
...

but in controller edytuj I have got this:
 50 sub edytuj : Local FormConfig {
 51  my ($self,$c,$nr) = @_;
 52 
 53  $nr && ($nr=~/\d/);
 54  if(my $grupa=$c->model('hubeDB::Umowy')->find_or_new({lpu=>$nr})) {
 55   my $form=$c->stash->{form};
 56   if($form->submitted_and_valid) {
 57    eval { my $wynik=$form->save_to_model($grupa); };
 58    $c->response->redirect($c->uri_for('/umowy/lista'));
 59   }
 60   else {
 61    $form->defaults_from_model($grupa);
 62   }
 63  }
 64  else {
 65   $c->response->redirect($c->uri_for('/umowy/lista'));
 66  }
 67  #my $form=$c->stash->{form};
 68 
 69 }

My problem is: it doesn't work... I try find definition relationships in formfu, but nothing... 
Would you like to help me with this? Links, examples etc. I paused my adventure with catalyst by this....


Thx!
jacek ch. (neila)




</select>





More information about the Catalyst mailing list