What can be placed in the _schema Model field to create a custom model without tables?

I already read this "trick" in the cookbook: http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable

Now I would like to create a custom schema for my model, but the format for this array does not exist. For example, I don’t know what should I use for the bool type: "boolean" or "bool"?

If I want to get a "select box" when I use $ this-> Form-> input, what type should I supply? Should I create a hasMany relation (with 2 non-standard models)?

0
source share
1 answer

the docs are here: http://book.cakephp.org/2.0/en/models/model-attributes.html#schema

here is an example contact form: http://www.dereuromark.de/2011/12/15/tools-plugin-part-2-contact-form/

As for booleans (tinyint 1):

protected $_schema = array( 'status' => array( 'type' => 'boolean', 'length' => 1, 'default' => 0, 'null' => false, 'comment' => 'some optional comment' ), ); 

TIPP: if you want to quickly find it yourself:

create the "Apples" table and the Apple model and add all the field types that you want to debug then call the model diagram () as follows:

 debug($this->Apple->schema()); 

This is how I confirmed it.

And for the second part - I use the following ENUM solution for samples, if the values ​​can be considered "static": http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/ otherwise you must use the relationships described in the cookbook or in the data source of the array.

+7
source

Source: https://habr.com/ru/post/1437263/


All Articles