Re: About a mysql query
Nope, won't work. I've tried 'FOO() AS Table.field', 'FOO() AS `Table`.`field`' and 'FOO() AS `Table.field`'. The first 2 are invalid SQL, the last one isn't parsed by cake properly. afterFind() is the only way I've found to do this. On Oct 23, 3:43 am, dardosordi <[EMAIL PROTECTED]> wrote: > You can try putting 'SUBSTRING_INDEX("content", " ", 20) AS > Announcement.teaser' > > On Oct 22, 6:06 am, grigri <[EMAIL PROTECTED]> wrote: > > > Model::findAll() only indexes fields that are present in the database; > > anything else is returned as you see (numeric index). > > > You can write an afterFind() callback in your model to insert the > > fields into the correct positions. > > > On Oct 19, 11:15 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > > Hey, > > > > I am trying to do this: > > > $this->set('announcements', $this->Announcement->findAll(null, > > > array('id', 'name','SUBSTRING_INDEX("content", " ", 20) AS teaser', > > > 'pic_filename'), 'add_date DESC')); > > > > and it doesn't work properly .. > > > > here is part of the dump of the resulting object: > > > array(2) { > > > ["Announcement"]=> > > > array(3) { > > > ["id"]=> > > > string(1) "2" > > > ["name"]=> > > > string(18) "Stire senzationala" > > > ["pic_filename"]=> > > > string(8) "nicu.jpg" > > > } > > > [0]=> > > > array(1) { > > > ["teaser"]=> > > > string(7) "content" > > > } > > > } > > > > Any help would be apreciated! > > > > Thx --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: About a mysql query
You can try putting 'SUBSTRING_INDEX("content", " ", 20) AS Announcement.teaser' On Oct 22, 6:06 am, grigri <[EMAIL PROTECTED]> wrote: > Model::findAll() only indexes fields that are present in the database; > anything else is returned as you see (numeric index). > > You can write an afterFind() callback in your model to insert the > fields into the correct positions. > > On Oct 19, 11:15 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > Hey, > > > I am trying to do this: > > $this->set('announcements', $this->Announcement->findAll(null, > > array('id', 'name','SUBSTRING_INDEX("content", " ", 20) AS teaser', > > 'pic_filename'), 'add_date DESC')); > > > and it doesn't work properly .. > > > here is part of the dump of the resulting object: > > array(2) { > > ["Announcement"]=> > > array(3) { > > ["id"]=> > > string(1) "2" > > ["name"]=> > > string(18) "Stire senzationala" > > ["pic_filename"]=> > > string(8) "nicu.jpg" > > } > > [0]=> > > array(1) { > > ["teaser"]=> > > string(7) "content" > > } > > } > > > Any help would be apreciated! > > > Thx --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: About a mysql query
Model::findAll() only indexes fields that are present in the database; anything else is returned as you see (numeric index). You can write an afterFind() callback in your model to insert the fields into the correct positions. On Oct 19, 11:15 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hey, > > I am trying to do this: > $this->set('announcements', $this->Announcement->findAll(null, > array('id', 'name','SUBSTRING_INDEX("content", " ", 20) AS teaser', > 'pic_filename'), 'add_date DESC')); > > and it doesn't work properly .. > > here is part of the dump of the resulting object: > array(2) { > ["Announcement"]=> > array(3) { > ["id"]=> > string(1) "2" > ["name"]=> > string(18) "Stire senzationala" > ["pic_filename"]=> > string(8) "nicu.jpg" > } > [0]=> > array(1) { > ["teaser"]=> > string(7) "content" > } > } > > Any help would be apreciated! > > Thx --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
About a mysql query
Hey, I am trying to do this: $this->set('announcements', $this->Announcement->findAll(null, array('id', 'name','SUBSTRING_INDEX("content", " ", 20) AS teaser', 'pic_filename'), 'add_date DESC')); and it doesn't work properly .. here is part of the dump of the resulting object: array(2) { ["Announcement"]=> array(3) { ["id"]=> string(1) "2" ["name"]=> string(18) "Stire senzationala" ["pic_filename"]=> string(8) "nicu.jpg" } [0]=> array(1) { ["teaser"]=> string(7) "content" } } Any help would be apreciated! Thx --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---