If UUIDs or auto-increments are a concern because you are entering that many 
records, you'd never do anything other than put it in a table and have a model. 
You almost suggest that having no constraint on the id column is a good thing. 
What happens when 'banana' gets inserted into it when it really ought to be a 
number? Integrity is all about constraint.

Of course it has something to do with his question. You can't separate what is 
easy and right for the developer with what is right and easy for the consumer. 
If it's in the database you do a join and bring in the value in place of the 
id. You cannot do that once the data is separated from the code. Today it's in 
CakePHP, tomorrow it's being accessed via some other iPad interface that 
doesn't have the luxury of peeking into the right piece of code to interpret 
what that odd column means.

MVC separates the layers of the application. If it's data, it goes in the 
Model. If it's in a Model, it ought to go in a table.

How much hassle is it to create a table, an index, a constraint and a model?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 19 May 2011, at 19:02, gremlin wrote:

> Yeah but one side effect of the array datasource is that there is no
> constraint on your 'id' column. You can make it a text string - as
> long as it is unique in the $records for each records id field there
> is no reason to use an integer. The array datasource doesn't auto-
> increment or care about uuids or column types.
> 
> Second, the question was specifically about the right way to do this
> in MVC - CakePHP specifically. Worrying about how to do something
> outside of cake with this data isn't in the scope of his question.
> Also, any system that uses db storage for the genders is going to have
> this issue. If you care you can easily enough do a structure similar
> to ( id => auto increment int, slug => male/female/etc, key => 'M/F/
> etc', value=>'Male/Female/etc' ) and simply do a key / value lookup to
> generate options and the slug field for lookups based on gender. Easy.
> I think the hardest part of the above solution would be overriding the
> Gender:find( ) for generating list type finds. That might even be
> overkill since you can pass options to the find( 'list' ) call.
> 
> I still think the configure method would be the easiest - plus you can
> store form helper defaults in there, field defaults for field types
> and then all of the other little options sets and messages that get
> used could be in one place.
> 
> 
> On May 19, 7:22 am, Jeremy Burns | Class Outfit
> <jeremybu...@classoutfit.com> wrote:
>> When you later do an extrapolation of this data (possibly outside of Cake) 
>> there is a disconnect between the id and the value, making it hard to 
>> interpret:
>> 
>> "What does '3' mean? Let's go and look in the code - oops, I don't know how 
>> to."
>> 
>> Jeremy Burns
>> Class Outfit
>> 
>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>> On 19 May 2011, at 15:19, gremlin wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Personally I dislike all the methods mentioned.
>> 
>>> This is configuration data - load it from a config file. In your
>>> bootstap.php do a Configure::load( 'forms' ); somewhere near the
>>> bottom.
>> 
>>> Then in /app/config/forms.php
>> 
>>> put the configuration information for the select options.
>> 
>>> $config[ 'Forms' ][ 'genderSelectOptions' ] = array( 'M' => 'Male',
>>> 'F' => 'Female' );
>> 
>>> and load them in your views with
>>> Configure::read( 'Forms.genderSelectOptions' ) when you need the
>>> options loaded into the form helper.
>> 
>>> http://book.cakephp.org/view/924/The-Configuration-Class
>> 
>>> Another option - more robust than the method above and similar to the
>>> Model options mentioned above is to use an ArrayDatasource and have a
>>> Gender model that relates to the User (or whatever model has the need
>>> to select a gender)
>> 
>>> https://github.com/cakephp/datasources
>> 
>>> On May 19, 4:50 am, Jeremy Burns | Class Outfit
>>> <jeremybu...@classoutfit.com> wrote:
>>>> I think this is the best advice (I always advocate storing everything in 
>>>> the database) but there might just be the odd exception.
>> 
>>>> Jeremy Burns
>>>> Class Outfit
>> 
>>>> jeremybu...@classoutfit.comhttp://www.classoutfit.com
>> 
>>>> On 19 May 2011, at 12:39, djogo wrote:
>> 
>>>>> I think it depends whether you store this value in the database or
>>>>> not.
>> 
>>>>> If you do, the right thing is to create a table and then accessing it
>>>>> by a model. For a very good reason, in big projects you don't want to
>>>>> lose time thinking "is it a table or a array within a controller? in
>>>>> which controller is it?".
>> 
>>>>> Also, if this value is used in the database, later you may want to
>>>>> write a single query to retrieve this data, and run this query on the
>>>>> console (or a backup script, e.g.) and suddenly you realized that that
>>>>> tied you to cakephp.
>> 
>>>>> If you think that's the best solution (to keep this data as an array),
>>>>> the ideal solution (in my mind) would be to have a Model which access
>>>>> this array instead of a database table. If you only need it for drop
>>>>> boxes, maybe this:
>> 
>>>>> app/models/gender.php
>> 
>>>>> class Gender // extends nothing
>>>>> {
>>>>>  var $data = array( 'M' => 'Male', 'F' => 'Female' );
>> 
>>>>>  function find($type,$opt=null)
>>>>>  {
>>>>>    if ( $type='list' ) return $data;
>>>>>    throw new exception(" find('$type') in bogus model isn't supported
>>>>> - maybe it's time to use a real table." );
>>>>>  }
>> 
>>>>> }
>> 
>>>>> I know, it's ugly, but what's the upside of all this coding? All data
>>>>> in accessible by models, and you didn't wrote a lot of database tables
>>>>> that will never change.
>> 
>>>>> I would love proper support of "virtual" models that access data on a
>>>>> CSV, static array, etc.
>> 
>>>>> dfcp
>> 
>>>>> On 18 maio, 15:46, Jason Mitchell <jason.a.mitch...@gmail.com> wrote:
>>>>>> I have in a controller an array containing data used on the view to 
>>>>>> populate
>>>>>> a drop down. I put it on the controller, so the array could be used by
>>>>>> multiple views associated with that controller (create, edit). 
>>>>>> Additionally,
>>>>>> it means that if I do ever have to change it, I just have to change it 
>>>>>> once
>>>>>> (yup, lazy).
>> 
>>>>>> Because the data is relatively static, and is used in only isolated
>>>>>> instances, it didn't seem to be worth the effort of creating a model for
>>>>>> that data, and establishing a relationship between models. And, putting 
>>>>>> it
>>>>>> on the controller, worked.
>> 
>>>>>> Admittedly, I'm new to MVC, but this really doesn't seem to jive 
>>>>>> definition.
>>>>>> Am I doing something wrong?  If so, how would one but this on the model,
>>>>>> short of some sort of association with another model?
>> 
>>>>>> --
>>>>>> J. Mitchell
>> 
>>>>> --
>>>>> Our newest site for the community: CakePHP Video 
>>>>> Tutorialshttp://tv.cakephp.org
>>>>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp 
>>>>> others with their CakePHP related questions.
>> 
>>>>> To unsubscribe from this group, send email to
>>>>> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
>>>>> athttp://groups.google.com/group/cake-php
>> 
>>> --
>>> Our newest site for the community: CakePHP Video 
>>> Tutorialshttp://tv.cakephp.org
>>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
>>> others with their CakePHP related questions.
>> 
>>> To unsubscribe from this group, send email to
>>> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
>>> athttp://groups.google.com/group/cake-php
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to