D'oh! Read 'mssql' as 'mysql'. My bad.

The cake MS SQL datasource does a similar thing to postgres (with the
double underscore), but it looks like you won't be able to use the
same workaround because the field mappings are pre-calculated.

You can still use a behavior though, or extend the DboMssql class and
override fetchResults(), looks like it might be a bit trickier than
for mysql though.

On Jan 17, 3:16 pm, grigri <[EMAIL PROTECTED]> wrote:
> mysql resultsets identify the originating table and field name (table
> can be aliased), and cake uses this information to build the array.
>
> So if you have SELECT `Thing`.`eggs` FROM things AS `Thing` ...
>
> Then cake knows that field is from the `Thing` model and puts it in
> the appropriate array. This is necessary because hasOne and belongsTo
> associations use joins, so fields from several tables (models) can be
> returned in the same resultset.
>
> If you specify an alias for the field : SELECT `Thing`.`eggs` AS
> `bacon` FROM things AS `Thing`
>
> Then in the resultset, the `bacon` field has no associated table, and
> therefore no model. This is why cake puts it in a [0] index, because
> it doesn't (and can't) know the table/model it came from.
>
> On the other hand, PostgreSQL resultsets do not identify the
> originating table, so cake fakes it buy creating an alias consisting
> of the table name, double underscore, then the field name, which is
> then parsed back from the resultset into model/field. So if you were
> using postgres, you could take advantage of this to create custom
> aliases:
>
> $this->Thing->find('all', array('fields' => 'Thing.eggs AS
> Thing__bacon'));
>
> would generate $data[Thing][bacon]
>
> Since you're using mysql, you can use a behavior to post-transform the
> fields (http://openpaste.org/en/3929/allows you to specify field
> aliases as `Table.field`, there are similar things around
> (TrueFieldBehavior, I seem to remember).
>
> You could also extend the dbo_mysql class with your own, and override
> the resultSet() method to handle aliases in a similar way to postgres,
> or any convention you'd like. This would probably be less resource-
> intensive.
>
> On Jan 17, 2:42 pm, hydra12 <[EMAIL PROTECTED]> wrote:
>
> > I can't help you with mssql or aliases, but I might be able to help
> > with the json stuff.  If I understand you correctly, you are wanting
> > to get your data into a good json format (ie - not have the data
> > nested in so many arrays).  You might Set::extract().  You can find a
> > short tutorial 
> > here:http://www.thinkingphp.org/2007/02/24/cake-12s-set-class-eats-arrays-...
>
> > I have an example that uses this to create a json string 
> > here:http://www.ntatd.org/mark/?p=29.
>
> > I hope that helps some.  I know it's not what you actually asked for,
> > but maybe it will help in the mean time.
>
> > hydra12
>
> > On Jan 16, 7:14 am, Fraed <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > i am using Cakephp 1.2.0.6311 beta with mssql.
>
> > > Im trying to use Alias-Names in the findAll()-Method. (eg in SQL:
> > > SELECT name AS text from table). Everytime setting up the field
> > > parameter like array('name AS text') the returned Array-Structure is
> > > unusable. A value would be accessable as:
>
> > > $data[0][Model][0][Model][0]['text'] instead of $data[0][Model][text]
>
> > > Fields without an Alias have their right place.
>
> > > Is there any way to work with aliases and set up the Array structure
> > > correctly? This would be very helpful to encode some json_data and
> > > maybe also for other things. Maybe the defnition in the field array is
> > > wrong. But theres no hint where aliases can be defined on other
> > > points. Is it working with mysql? Cant test it here in Company.
>
> > > Thanks for your help
>
> > > Fraed
--~--~---------~--~----~------------~-------~--~----~
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