Thursday, March 31, 2011

Re: Datasource schemas defined into models

Overload DataSource::isInterfaceSupported() method to not report
listSources() method as available if you don't like it so much.

On Mar 31, 4:34 pm, Clément Hallet <clem...@challet.eu> wrote:
> I overloaded the $mydatasource->describe() method to return the $model->_schema value ($model comes as a parameter to describe). It would
>
> work but an other issue (at least, it seems to be for me).
>
> My real issue is elsewhere and I wonder if it's a mistake in the
> global design. Let's focus on it :
>
> The function Model->setSource() is called to link a model to a table.
> While doing it, there is the next test : "if($db->isInterfaceSupported('listSources'))" and erase the $model->_schema
>
> from the schema if true. I guess it's done to later rely on a schema
> coming from the datasource.
>
> And so if no schema is coming from the datasource, the $model->_schema
> would be used instead. But it's not ! because even when not
> implementing the "mydatasource->listSources" method, it comes from the
> Datasoure inheritance. It means that every one datasource (according
> it extends DataSource) can't rely on its $models->_schema (because
> they're always reseted).
>
> The aim of this inherited method is to cache the sources ant it's
> called internally by its overloading methods ("parent::listSources()")
> but it can't be a replacement (because the cache may not be already
> setted). So there is no point to have the same method names and get
> inheritance.
>
> I made the according changes herehttp://goo.gl/QTBtJand would like
> to have others' opinion before to make a pull request.
>
> Please let me know if I missed something in that description.
>
> On 30 mar, 04:43, "Dr. Loboto" <drlob...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Model have schema() method which call describe() method of data source
> > if supported. For manual per-model schemas you can override its
> > schema() method. For datasource-managed schemas you should take a look
> > into its describe() method.
>
> > On 29 мар, 03:50, Clément Hallet <clem...@challet.eu> wrote:
>
> > > Hello CakePHP,
>
> > > Trying to implement a CouchDB datasource and to closely follow the
> > > CakePHP guidelines,
> > > I'm in a trick situation :
>
> > > When saving a new record, it's required to have the fields matching
> > > the schema :https://github.com/cakephp/cakephp/blob/master/cake/libs/model/model....
> > > So, i put a $_schema in my model to match what i want to save.
>
> > > The problem is that this schema is automatically reseted to "array()"
> > > at initialization :https://github.com/cakephp/cakephp/blob/master/cake/libs/model/model....
>
> > > Even when removing the "listSources" method from my Datasource, it's
> > > still reseted because of the test "$db->isInterfaceSupported('listSources')"  :
>
> > > In fact my datasource extends "Datasource" (i think it's required)
> > > which have it's own "listSources" method for caching children ones.
>
> > > So I would like to ask : is this Datasource->listSources method is
> > > compatible with per-Model defined schemas ? or am I doing wrong ?
>
> > > --
> > > Clément

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: