Re: association model
Have tried many different wayes, but with no success. I can't think out how to populate a join table which has more than two fields. In the index controller I 'm using the following: $this-set('langs', $this-Lang-findAll()); In the form: .. input fields for the seasons table ... $html-input('Season/Year'); . ... input fields for the seasons_langs table ?php foreach ($langs as $lang): ? Name: input type=text name=langData[?= $lang['Lang']['lang_id'] ?][SeasonLang][info] / ?php endforeach; ? So, in the controller I get an array: $this-params['form']['langData'][1][SeasonLang][Info] and $this-params['form']['langData'][2][SeasonLang][Info] (suppose we have two languages) Then I make a record for the season : $this-Season-save($countries_data) and then I build the arrays for the seasons_langs: $seasons_langs_data['SeasonLang']['season_id'] = $this-Season-getLastInsertID(); foreach ($this-params['form']['langData'] as $key = $value) { $countries_langs_data['SeasonLang']['lang_id'] = $key; $countries_langs_data['SeasonLang']['name'] = $value['SeasonLang']['info']; $this-Season-SeasonLang-save($seasons_langs_data); } Then in the seasons_langs table I have only one record. Cakephp saves the record for the first language in the first iteration and then just updates this record on the second iteration. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: association model
Dolorian wrote: Then I make a record for the season : $this-Season-save($countries_data) this is wrong. I mean: $this-Season-save($this-params['form']['Season']) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: association model
I would bet on HABTM class Season extends AppModel { var $hasAndBelongsToMany = array ( 'Lang' = array('className' = 'Lang', 'joinTable' = 'seasons_langs')); } class Lang extends AppModel { var $hasAndBelongsToMany = array ( 'Season' = array('className' = 'Season', 'joinTable' = 'seasons_langs')); } et voilĂ .. That should work... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: association model
Thanks for the answer. I have two questions on it: 1. I need to add an array item in Langs for every table that use langs, right ? 2. 'seasons_langs' has a third filed 'info', which actually holds the specific language information (for the other tables there could be more such fields). How am I supposed to populate this fild, when the 'seasons_langs' is determined as joinTable ? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: association model
Dolorian wrote: Thanks for the answer. I have two questions on it: 1. I need to add an array item in Langs for every table that use langs, right ? 2. 'seasons_langs' has a third filed 'info', which actually holds the specific language information (for the other tables there could be more such fields). How am I supposed to populate this fild, when the 'seasons_langs' is determined as joinTable ? Hmm, I was too quick to answer... I fear that you need to create a Model for seasons_langs, then and have hasMany and belongsTo tables. To get a hint, you could perhaps see what has been done for Acl, with Aro, Aco, and AroAco Models... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---