Eingaben in unterschiedliche Models speichern

24 views
Skip to first unread message

Jerome Walitzek

unread,
Oct 25, 2012, 10:23:52 AM10/25/12
to cakep...@googlegroups.com
Hallo Zusammen,

seit geraumer Zeit versuche ich folgendes Szenario. Evtl. kann ja jemand helfen.

Ich habe die Models FactsA, FactsB, FactsC, .... bis FactsQ
Da die Anzahl der Felder soviele sind musste ich dies so unterteilen. MySQL macht da ja einem einen Strich durch die Rechnung :-)
Jedenfalls möchte ich nun eine einzigste Eingabe Maske "Add" haben in der ich alle Felder ausfüllen kann und die dann durch die entsprechenden Models in die richtigen Datenbank Tabell gespeichert werden.

Was ich nun schon versucht habe:
Im Model FactsA:
public $hasMany = array('FactsB','FactsC','FactsD','FactsE','FactsF','FactsG','FactsH','FactsI','FactsJ','FactsK','FactsL','FactsM','FactsN','FactsO','FactsP','FactsQ');
Im Model FactsB bis FactsQ:
public $belongsTo = array('FactsA');

und dann das ganze durch im Controller durch "saveAll" umzusetzen.
Aber irgendwie, ... es klappt nicht. Hat jemand einen Rat oder eine gute Idee wie ich das ganze nun zum laufen bringe ?

Für Hilfe bin ich sehr dankbar.

Liebe Grüße
Jérome

Mark Kessler

unread,
Oct 25, 2012, 10:28:13 AM10/25/12
to cakep...@googlegroups.com
What you are trying to do looks suspicious to me. Maybe you should try a totally different approach. Can maybe you describe your Szenario?

2012/10/25 Jerome Walitzek <jerome....@t-online.de>

--
Bitte bei Fragen immer auch die aktuell verwendete cakePHP Version angeben und
wenn möglich auch das verwendete Betriebssystem und die PHP Version. Danke.
Sie erhalten diese Nachricht, weil Sie Mitglied sind von Google Groups-Gruppe "CakePHP-de für deutsche CakePHP Entwickler".
Für das Erstellen von Beiträgen in dieser Gruppe senden Sie eine E-Mail
an cakep...@googlegroups.com
Um sich von dieser Gruppe abzumelden, senden Sie eine E-Mail an cakephp-de-...@googlegroups.com
Weitere Optionen finden Sie in dieser Gruppe unter http://groups.google.com/group/cakephp-de?hl=de

Jerome Walitzek

unread,
Oct 25, 2012, 10:38:30 AM10/25/12
to cakep...@googlegroups.com
HI tinytiger,

of course i will give my best to describe it to you.

i have over 250 input fields. mysql can´t handle over 250 rows. so i split the rows into segments
FactsA till FactsQ

Now I would not have 17 individual add-views but only one.

And this is my Problem.
I opened the FactsA View and put all Fields into like this

<?php
echo $this->Form->create('FactsA');
echo $this->Form->input('modelname.fieldname', array('label' => false, 'class' => 'input full-width', 'div' => false));
...
...
...
echo $this->Form->end(__('Submit'));
?>

But nothing happens when i click on "Submit".
This is what i would like to to :-)

I hope what i explained was understandable

Nice Greetings
Jerome

Mark Kessler

unread,
Oct 25, 2012, 10:45:53 AM10/25/12
to cakep...@googlegroups.com
I think your approach will lead to very inefficient code. But if you want to do this, maybe you should change your model setup a bit in a way where there is a general model "Facts" which hasOne AFacts, BFacts, CFacts,...

With so many fields, I would suggest a more generic approach though where you have a model Facts which hasMany FieldValues where FieldValue is a model made up of the fields

id
param_name
param_value
created 
modified

Of course you have to write some controller code and model code so the creation and saving of models is handled properly.


2012/10/25 Jerome Walitzek <jerome....@t-online.de>

Jerome Walitzek

unread,
Oct 25, 2012, 11:00:44 AM10/25/12
to cakep...@googlegroups.com
that sounds very interesting.
i think your idea is great...

so let me think about it..

i will create a model with the fieldnames from you.
id is generated from datebase
param_name could be for example a "companyname"
param_value is for example model "FactsA"
created and modified are also automatic generated.

When I think about it I must, however, after each entry, such as company name, manager, and so on "Save" and then again on "Add". Or my thinking is wrong?

Jerome Walitzek

unread,
Oct 31, 2012, 5:22:56 AM10/31/12
to cakep...@googlegroups.com
hi tinytiger,

can you give me maybe a code example how the whole can be installed?
So I can get a better picture.

Thank you.

Mark Kessler

unread,
Oct 31, 2012, 5:50:42 AM10/31/12
to cakep...@googlegroups.com
Sorry, I dont have the time to create an elaborate code example right now but I will try to elaborate on my approach a bit.

The idea was to have a model that can be used as an aggregator for big amounts of data. An example could be a vehicle, for every type of vehicle there can be hundreds of attributes to describe the vehicle (model, color, combustion engine, date of manufactory etc.). So we have a model called Vehicle. I would use a model called VehicleFieldValue to store the attributes. I could also use a model VehicleType to describe different types of vehicles (SUV, Truck, Bus, etc,). Another model VehicleField would be used to define the different fields in every VehicleType.

It would look something like that::

Model "Vehicle":
Fields: id, vehicle_type_id, created, modified
Associations: belongsTo VehicleType, hasMany VehicleFieldValule

Model "VehicleType"
Fields: id, name, created, modified
Associations: hasMany Vehicle, hasAndBelongsToMany VehicleField

Model "VehicleField"
Fields: id, vehicle_type_id, name, created, modified
Associations hasAndBelongsToMany VehicleType, hasMany VehicleFieldValue

Mode "VehicleFieldValue"
Fields: id, vehicle_id, vehicle_field_id, value, created, modified

You will also need a tabel for the hasAndBelongsToMany Assoc called "vehicle_field_vehicle_type" with the fields:
vehicle_field_id, vehicle_type_id

You would need to make sure to build the correct add and edit views and also to properly save the VehicleFieldValue associated with the Vehicle correctly in the controller.

This approach is maby too complex but it would be very flexible.
 


2012/10/31 Jerome Walitzek <jerome....@t-online.de>

jerome

unread,
Oct 31, 2012, 6:24:02 AM10/31/12
to cakep...@googlegroups.com
Hi Tinytiger or Mark ;-)

Thank you.
Now I have
a better idea what you mean.
Think this version is actually better than 250 individual fields in separate tables.

Thank you
for the note and your advice.
I'll
even try to implement this.

jerome
Reply all
Reply to author
Forward
0 new messages