Are the two models joined with an association (hasMany, belongsTo etc) - even
if not directly?
If so, all you need to do is:
$variable = $this->Company->Role->find('all');
None of that model loading or db setting stuff - totally unneeded.
If the models aren't joined, join them if you can; it'll improve your whole app.
If they are not joined directly, you can just walk along the daisy chain:
$variable = $this->Company->Department->User->etc->etc->Role->find('all');
Jeremy Burns
Class Outfit
[email protected]
http://www.classoutfit.com
On 15 Feb 2011, at 00:05, Shinya Koizumi wrote:
> On Mon, Feb 14, 2011 at 12:58 PM, Jeremy Burns | Class Outfit
> <[email protected]> wrote:
> That all looks a little unusual. Can you explain in non-code terms what you
> are trying to do?
>
> Jeremy Burns
> Class Outfit
>
> [email protected]
> http://www.classoutfit.com
>
> On 14 Feb 2011, at 20:55, cake-learner wrote:
>
> > Very often i got this error and i had to do custom query why it's not
> > putting '*'?
> >
> > $this -> loadModel( 'Company.Role' );
> > $this -> Role -> useDbConfig = $this -> db_name;
> > $arrRoles = $this -> Role -> find( "all" );
> >
> > Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
> > check the manual that corresponds to your MySQL server version for the
> > right syntax to use near 'FROM `roles` AS `Role` WHERE 1 = 1' at
> > line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 535]
> >
> > Code | Context
> >
> > $sql = "SELECT FROM `roles` AS `Role` WHERE 1 = 1 "
> > $error = "1064: You have an error in your SQL syntax; check
> > the manual
> > that corresponds to your MySQL server version for the right syntax to
> > use near 'FROM `roles` AS `Role` WHERE 1 = 1' at line 1"
> >
> > --
> > 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
> > [email protected] For more options, visit this group at
> > http://groups.google.com/group/cake-php
>
> --
> 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
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php
>
> I am just trying to search on Model from different Controller.
>
> --
> 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
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php