Re: DB_FormBuilder
| From: | Markus Wolff | Date: | Thu, 18 Mar 2004 16:10:11 +0000 |
| Subject: | Re: DB_FormBuilder | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11364@lists.php.net to get a copy of this message | ||
David Thunman schrieb:
The flow is so that each item in table "measure" will have a file form field where I want to upload a file and then insert the file data into the "file" table. Then I use the "photos" table for the relation between the "measure" and "file" table. The problem is how to implement this in my FormBuilder Measure Class when I create the form. Is it possible for the FormBuilder to recognize such a relation from within the Measure Class, or do I have to create an instance of the File Class in the Measure Class. Sorry for this confusion, but I am a bit stuck here.This is a classic n:n relation, which is not handled by FormBuilder automatically. If all action goes from the measure class, your best bet is to implement a postProcess() method in which you fetch the information from the file field, make a new instance of the file class, insert a new record there, take the ID of your freshly-inserted measure record, make an instance of the photo class, put the new file_id and measure_id inside, and do an insert(). Careful: postProcess() is always triggered after processing the form data. Thus, it will not only be executed after an insert() operation, but also after an update() - so it's up to you to find out what kind of operation you're dealing with and act accordingly! That should to the trick, at least if I have understood you correctly... :-) But: This will actually make a new entry in the file _and_ photo table each time you make a new measure record. So basically, you're creating a 1:n relationship here and there's no need for a third table. From a user interface point of view it would be clearer (and also easier to code) to first let the user create a new measure record and then give him the possibility to add an arbitrary number of files (using a dedicated file upload form) to that existing record - you can then implement the postProcess() method in the file class, using the measure_id from the existin record... and then you'd have a true n:n relationship. Regards, Markus