First of all, the coupling would not be any looser even if you used
objects.  The component would just be tightly coupled to an object
property instead of an array key.  Second of all, this is what
afterFind is for.  If you have to make a database change which impacts
your code, you can use afterFind to act as an intermediary, and alter
the data before it goes elsewhere in the application.  Third of all,
since you always writing unit tests for your application, you will
always know exactly what breaks and where if you make a database
change.  You are using unit tests.... aren't you?

On Mar 21, 5:24 pm, "Sonic Baker" <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I'm looking for someone to give me a hug and tell me everything will be ok.
> Thinking in terms of low coupling of classes again, it struck me that
> passing your applications method parameters as associative arrays may be a
> step in the wrong direction. For example, I have a cake component to which I
> pass the result of a $this->Model->find(); The result is of course an
> associative array. Inside the component, I extract the keys I want and
> ignore the rest.  So I may take $params['Post']['title'] and ignore
> $params['Post']['comment'].
> However, if I happen to change the field names in the database table, the
> resulting array keys will also change. This means that not only will this
> change affect my Model, but it will also affect anything which is expecting
> the field name as a key. So if I change a field in the `posts` table from
> 'title' to 'some_title', my component will still be expecting
> $params['Post']['title'] and so, this part of the system is somewhat tightly
> coupled.
> The only solutions I can think of are:
>     (1) To avoid passing arrays as params and pass them as variables
> instead. This may lead to methods expecting a long list of parameters
> though. This can be ugly and confusing to the reader.
>     (2) Set up the params array to the expected structure before passing it
> to the component. However this still means a change in the database table
> will ripple through to the controller.
>
> Allowing the component to access the model itself will mean that the
> component is still coupled to a Model.
>
> Can anyone suggest alternatives, or at least stroke my forehead and tell me
> everything will be ok!
>
> Cheers,
>
> Sonic


--~--~---------~--~----~------------~-------~--~----~
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