Here is how I decided to deal with my problem.

I hope some knowledgeable user can confirm this is a good way to do
it. Anyway, I'll share my findings if it can help others.

I decided to use a model without table so I can use Model validation.

Here is my model (more on $fields at the bottom):

class QuantiteTotaleEnfouie extends AppModel {

        var $name = 'QuantiteTotaleEnfouie';
        var $useTable = false;
        var $fields = array(
                'annee' => 'integer',
                'mois' => 'integer',
                'quantite_type_id' => 'integer',
                'quantite_totale' => 'float',
                );

        var $validate = array(
                'annee' => array(
                                'required' => array('rule' => 'numeric'),
                                 ),
                'mois' => array(
                                'required' => array('rule' => 'numeric'),
                                 ),
                'quantite_type_id' => array(
                                'required' => array('rule' => 'numeric'),
                                 ),
                'quantite_totale' => array(
                                'required' => array('rule' => 'numeric'),
                                 ),
                );

}

I implemented the method suggested by Mariano here:
http://groups.google.com/group/cake-php/msg/ec7a19859608a453

except I changed loadInfo (which is now deprecated) by schema.

It use the $fields defined in the model to build the schema for my
model.

Here is the function I placed in app_model:

        function schema()
        {
                if ($this->useTable === false) {
                        $defaults = array(
                                'null' => false,
                                'default' => null,
                                'length' => null
                                );

                        $fields = array();

                        foreach($this->fields as $field => $type) {
                                $fields[] = am(array('name'=>$field,
                                        'type'=>$type), $defaults);
                        }

                        return new Set($fields);
                }

                return parent::schema();
        }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to