Re: Problems with CONCAT function

2009-03-22 Thread Chrillemeter

Thanks, it works. But it don't work when I use it with HABTM.

I have three tables

users | groups | groups_users


The habtm code in the model Group, looks like this

public $hasAndBelongsToMany =
array
(
'User' =
array
(
'className' = 'User',
'join_table' = 'groups_user',
'with' = 'GroupsUser',
'foreignKey' = 'group_id',
'associationForeignKey' = 'user_id',
'fields' =
array
(
'CONCAT(User.firstname,\'
\',User.lastname) AS full_name'
)
)
);


then I use this in the controller to get the result

$this-set('GroupUsers', $this-find('all'));



/ Christher

On Mar 21, 10:46 pm, mscdex msc...@gmail.com wrote:
 On Mar 21, 3:51 pm, Chrillemeter i...@christher.se wrote:

  Hello!

  I got a problem with $this-Model-find() and sql-functions such as
  CONCAT.

 This is a known problem and it happens when using any SQL functions.
 Teknoid has a solution for this issue 
 here:http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-field...

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~--~~~~--~~--~--~---



Re: Problems with CONCAT function

2009-03-22 Thread mscdex

On Mar 22, 5:43 am, Chrillemeter i...@christher.se wrote:
 Thanks, it works. But it don't work when I use it with HABTM.

Did you put the afterFind() fix code in just your User model? If so,
you'll need to also put it in your Group model or in your
app_model.php (if you want the fix to automatically be used by all
models).

 then I use this in the controller to get the result
 
 $this-set('GroupUsers', $this-find('all'));
 

If that's in your controller, $this-find('all') should be $this-
Group-find('all');
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~--~~~~--~~--~--~---



Re: Problems with CONCAT function

2009-03-22 Thread brian

Or put it in your AppModel so you don't need to think about it again.

On Sun, Mar 22, 2009 at 12:54 PM, mscdex msc...@gmail.com wrote:

 On Mar 22, 5:43 am, Chrillemeter i...@christher.se wrote:
 Thanks, it works. But it don't work when I use it with HABTM.

 Did you put the afterFind() fix code in just your User model? If so,
 you'll need to also put it in your Group model or in your
 app_model.php (if you want the fix to automatically be used by all
 models).

 then I use this in the controller to get the result
 
 $this-set('GroupUsers', $this-find('all'));
 

 If that's in your controller, $this-find('all') should be $this-
Group-find('all');
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~--~~~~--~~--~--~---



Problems with CONCAT function

2009-03-21 Thread Chrillemeter

Hello!

I got a problem with $this-Model-find() and sql-functions such as
CONCAT.

CODE
-
$this-User-find(
'all',
array(
'fields' = array(
'CONCAT(User.firstname,\' \'User.lastname)) AS 
full_name'
)
)
);


When I use sql function with find() it returns arrays lookin like
this.

RESULT
-
Array
(
[0] = Array
(
[0] = Array
(
[full_name] = Christher Lenander
)

)
)



I want the returned array to look like this

Array
(
[0] = Array
(
[User] = Array
(
[full_name] = Christher Lenander
)

)
)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~--~~~~--~~--~--~---



Re: Problems with CONCAT function

2009-03-21 Thread John Andersen

I haven't used this before, but reading the manual and checking your
code, I come up with this change:

'fields' = array( 'CONCAT( User.firstname, \' \',
User.lastname ) AS full_name' )

There was a mismatching of the brackets, one was actually inside the
CONCAT string.
Hope this helps :)
Enjoy,
   John


On Mar 21, 9:51 pm, Chrillemeter i...@christher.se wrote:
 Hello!

 I got a problem with $this-Model-find() and sql-functions such as
 CONCAT.

 CODE
 -
 $this-User-find(
         'all',
         array(
                 'fields' = array(
                                 'CONCAT(User.firstname,\' \'User.lastname)) 
 AS full_name'
                         )
         )
 );

[snip]
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~--~~~~--~~--~--~---



Re: Problems with CONCAT function

2009-03-21 Thread Chrillemeter

No change at all. Get the same result.

[0] = Array
(
[0] = Array
(
[full_name] = Christher Lenander
)

)


On Mar 21, 10:00 pm, John Andersen j.andersen...@gmail.com wrote:
 I haven't used this before, but reading the manual and checking your
 code, I come up with this change:

                 'fields' = array( 'CONCAT( User.firstname, \' \',
 User.lastname ) AS full_name' )

 There was a mismatching of the brackets, one was actually inside the
 CONCAT string.
 Hope this helps :)
 Enjoy,
    John

 On Mar 21, 9:51 pm, Chrillemeter i...@christher.se wrote:

  Hello!

  I got a problem with $this-Model-find() and sql-functions such as
  CONCAT.

  CODE
  -
  $this-User-find(
          'all',
          array(
                  'fields' = array(
                                  'CONCAT(User.firstname,\' \'User.lastname)) 
  AS full_name'
                          )
          )
  );

 [snip]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~--~~~~--~~--~--~---



Re: Problems with CONCAT function

2009-03-21 Thread mscdex

On Mar 21, 3:51 pm, Chrillemeter i...@christher.se wrote:
 Hello!

 I got a problem with $this-Model-find() and sql-functions such as
 CONCAT.

This is a known problem and it happens when using any SQL functions.
Teknoid has a solution for this issue here:
http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~--~~~~--~~--~--~---