Re: How to "custom belongsto" in CakePHP 2?
I'm still trying but there's no luck : ( On 3 ene, 17:41, Cristian Deluxe wrote: > Thanks AD7six, i also tried it in my previous test but Cake never > render the page, it seems to make a loop and it fails with this error: > > Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp > \htdocs\MyAppName\trunk\lib\Cake\Model\Datasource\DboSource.php on > line 1436 > > var $belongsTo = array( > 'Wdevice' => array( > 'className' > => 'Wdevice', > 'foreignKey' > => false, > 'conditions' > => array('Wdevice.device_mac = > Radpostauth.username') > > ) > ); > > If i do the SQL query in phpMyAdmin it works correctly: > > Mostrando registros 0 - 29 ( 50 total, La consulta tardó 0.2787 seg) > [id: 20179 - 20130] > (Sorry for the Spanish) > > SELECT `Radpostauth`.`id` , `Radpostauth`.`username` , > `Radpostauth`.`pass` , `Radpostauth`.`reply` , > `Radpostauth`.`authdate` , `Wdevice`.`id` , > `Wdevice`.`wcontract_id` , `Wdevice`.`device_mac` , > `Wdevice`.`wdevices_model_id` , `Wdevice`.`created` , > `Wdevice`.`modified` > FROM `radpostauth` AS `Radpostauth` > LEFT JOIN `wdevices` AS `Wdevice` ON ( `Wdevice`.`device_mac` = > `Radpostauth`.`username` ) > WHERE 1 =1 > ORDER BY `Radpostauth`.`id` DESC > LIMIT 50 > > And if i write: > 'conditions' > => array('Wdevice.device_mac = > Radpostauth.username' => '') > > It works (don't enter in a loop) but the query fails: > > SELECT `Radpostauth`.`id` , `Radpostauth`.`username` , > `Radpostauth`.`pass` , `Radpostauth`.`reply` , > `Radpostauth`.`authdate` , `Wdevice`.`id` , > `Wdevice`.`wcontract_id` , `Wdevice`.`device_mac` , > `Wdevice`.`wdevices_model_id` , `Wdevice`.`created` , > `Wdevice`.`modified` > FROM `radpostauth` AS `Radpostauth` > LEFT JOIN `wdevices` AS `Wdevice` ON ( `Wdevice`.`device_mac` = > `Radpostauth`.`username` '') // <- note the ( '' ) > WHERE 1 =1 > ORDER BY `Radpostauth`.`id` DESC > LIMIT 50 > > SQLSTATE[42000]: Syntax error or access violation: 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 ''') WHERE 1 = 1 > ORDER BY `Radpostauth`.`id` desc LIMIT 50' at line 1 > > So i don't know what to do now : ( > > Thanks for your help guys : ) > > On 3 ene, 12:19, AD7six wrote: > > > > > > > > > On Jan 3, 11:23 am, CristianDeluxe > > wrote: > > > > Hey thanks : ) > > > > I've tried this but seems like CakePHP doesn't parse the condition > > > correctly: > > > > var $belongsTo = array( > > > 'Wdevice' => array( > > > > > > 'className' => 'Wdevice', > > > > > > 'foreignKey' => false, > > > > > > 'conditions' => array('Wdevice.device_mac' => > > > 'Radpostauth.username') > > > If the above did what you wanted cake would be rife with sql injection > > problems. Thankfully it does exactly what you asked and tests where > > device_mac = the string you've typed in the conditions. > > > You want > > array('Wdevice.device_mac = Radpostauth.username') > > > probably. > > > AD -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: How to "custom belongsto" in CakePHP 2?
Thanks AD7six, i also tried it in my previous test but Cake never render the page, it seems to make a loop and it fails with this error: Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp \htdocs\MyAppName\trunk\lib\Cake\Model\Datasource\DboSource.php on line 1436 var $belongsTo = array( 'Wdevice' => array( 'className' => 'Wdevice', 'foreignKey' => false, 'conditions' => array('Wdevice.device_mac = Radpostauth.username') ) ); If i do the SQL query in phpMyAdmin it works correctly: Mostrando registros 0 - 29 ( 50 total, La consulta tardó 0.2787 seg) [id: 20179 - 20130] (Sorry for the Spanish) SELECT `Radpostauth`.`id` , `Radpostauth`.`username` , `Radpostauth`.`pass` , `Radpostauth`.`reply` , `Radpostauth`.`authdate` , `Wdevice`.`id` , `Wdevice`.`wcontract_id` , `Wdevice`.`device_mac` , `Wdevice`.`wdevices_model_id` , `Wdevice`.`created` , `Wdevice`.`modified` FROM `radpostauth` AS `Radpostauth` LEFT JOIN `wdevices` AS `Wdevice` ON ( `Wdevice`.`device_mac` = `Radpostauth`.`username` ) WHERE 1 =1 ORDER BY `Radpostauth`.`id` DESC LIMIT 50 And if i write: 'conditions' => array('Wdevice.device_mac = Radpostauth.username' => '') It works (don't enter in a loop) but the query fails: SELECT `Radpostauth`.`id` , `Radpostauth`.`username` , `Radpostauth`.`pass` , `Radpostauth`.`reply` , `Radpostauth`.`authdate` , `Wdevice`.`id` , `Wdevice`.`wcontract_id` , `Wdevice`.`device_mac` , `Wdevice`.`wdevices_model_id` , `Wdevice`.`created` , `Wdevice`.`modified` FROM `radpostauth` AS `Radpostauth` LEFT JOIN `wdevices` AS `Wdevice` ON ( `Wdevice`.`device_mac` = `Radpostauth`.`username` '') // <- note the ( '' ) WHERE 1 =1 ORDER BY `Radpostauth`.`id` DESC LIMIT 50 SQLSTATE[42000]: Syntax error or access violation: 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 ''') WHERE 1 = 1 ORDER BY `Radpostauth`.`id` desc LIMIT 50' at line 1 So i don't know what to do now : ( Thanks for your help guys : ) On 3 ene, 12:19, AD7six wrote: > On Jan 3, 11:23 am, Cristian Deluxe > wrote: > > > Hey thanks : ) > > > I've tried this but seems like CakePHP doesn't parse the condition > > correctly: > > > var $belongsTo = array( > > 'Wdevice' => array( > > 'className' > > => 'Wdevice', > > > > 'foreignKey' => false, > > > > 'conditions' => array('Wdevice.device_mac' => > > 'Radpostauth.username') > > If the above did what you wanted cake would be rife with sql injection > problems. Thankfully it does exactly what you asked and tests where > device_mac = the string you've typed in the conditions. > > You want > array('Wdevice.device_mac = Radpostauth.username') > > probably. > > AD -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: How to "custom belongsto" in CakePHP 2?
Hey thanks : ) I've tried this but seems like CakePHP doesn't parse the condition correctly: var $belongsTo = array( 'Wdevice' => array( 'className' => 'Wdevice', 'foreignKey' => false, 'conditions' => array('Wdevice.device_mac' => 'Radpostauth.username') ) ); SELECT `Radpostauth`.`id`, `Radpostauth`.`username`, `Radpostauth`.`pass`, `Radpostauth`.`reply`, `Radpostauth`.`authdate`, `Wdevice`.`id`, `Wdevice`.`wcontract_id`, `Wdevice`.`device_mac`, `Wdevice`.`wdevices_model_id`, `Wdevice`.`created`, `Wdevice`.`modified` FROM `radpostauth` AS `Radpostauth` LEFT JOIN `wdevices` AS `Wdevice` ON (`Wdevice`.`device_mac` = 'Radpostauth.username') WHERE 1 = 1 ORDER BY `Radpostauth`.`id` desc LIMIT 50 It fails on: ON (`Wdevice`.`device_mac` = 'Radpostauth.username') must be: ON (`Wdevice`.`device_mac` = `Radpostauth`.`username`) Because if not SQL will try to match `Wdevice`.`device_mac` against string "Radpostauth.username" and it don't work. I've tried to change it but i can't make it work Thanks for your help On 1 ene, 08:42, Geoff Douglas wrote: > BelongsTo is simply a left join, (on the retrieval side)... > > I think what you are looking for is the Relationship conditions option. > (Which will create the ON statement in SQL) > > So what you want is something that looks like... > > Radpostauth Model... > > var $belongsTo = array( > > 'Wdevice' => array( > > 'className' => 'Wdevice', > > 'foreignKey' => false, > > 'conditions' => array( > > Wdevice.device_mac = radpostauth.username > > ) > > ) > > ); -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: How to "custom belongsto" in CakePHP 2?
Any way? -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
How to "custom belongsto" in CakePHP 2?
HI i'm working with a external database (RADIUS) that follows the next structure: CREATE TABLE IF NOT EXISTS `radpostauth` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `pass` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `reply` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `authdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19082 ; and in my app i have another table that follows the CakePHP conventions CREATE TABLE IF NOT EXISTS `wdevices` ( `id` int(11) NOT NULL AUTO_INCREMENT, `wcontract_id` int(11) NOT NULL, `device_mac` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `wdevices_model_id` int(11) NOT NULL, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; What work ok with associations (ie: Wcontract, Wdevice) but i'm trying to make an belongsto association where: radpostauth.username = wdevices.device_mac Currently it's works if i do a hasMany association: class Radpostauth extends AppModel { public $useDbConfig = 'radius'; var $name = 'Radpostauth'; public $useTable = 'radpostauth'; var $hasMany = array( 'Wdevice' => array( 'className' => 'Wdevice', 'foreignKey' => false, 'finderQuery' => ' SELECT Wdevice.* FROM radpostauth, wdevices AS Wdevice WHERE radpostauth.id={$__cakeID__$} AND Wdevice.device_mac = radpostauth.username ORDER BY Wdevice.id DESC LIMIT 0, 30;' ) ); } --- Sample return: Array ( [Radpostauth] => Array ( [id] => 19061 [username] => 00:11:22:33:44:55 [pass] => [reply] => Access-Accept [authdate] => 2011-12-28 12:57:12 ) [Wdevice] => Array ( [0] => Array ( [id] => 1 [...] But it's not the best way to do it because a radpostauth will be have always just one Wdevice associated so i would like to know if there are some way to do this kind of association with belongsTo, hasOne, etc.. Thanks : ) -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php