Hi, As 'venues' table has 'city_id', the form field name should be 'city_id' and not 'cities'.
Amit Badkas PHP Applications for E-Biz: http://www.sanisoft.com On Wed, Nov 24, 2010 at 5:48 AM, lash <[email protected]> wrote: > I have a view doing: > > echo $form->input('cities'); > > and a controller doing: > > function edit($id = null) { > $this->set('cities', $this->Venue->City->find('list')); > $this->Venue->id = $id; > if (empty($this->data)) { > $this->data = $this->Venue->read(); > } else { > $this->data['Venue']['city_id'] = $this->data['Venue']['cities'] > ['id']; > $venue = $this->Venue->save($this->data); > if (!empty($venue)) { > $this->Session->setFlash('Your venue has been saved.'); > $this->redirect(array('action' => 'index')); > } > } > } > > DB table names are cities and venues (id columns in both tables are > named id) > venue belongsTo city. > foreignKey is city_id in the venue table. > > The "cities" select box doesn't select the current value, only the top > value of the option list. > As far as I can see I'm following naming conventions, and this should > be working out of the box. The data is stored correctly in the db, so > I know the relation works. > > It works if I add to the controller: > > $this->set('venue', $this->Venue->read()); > > and edit the input function in the view to: > > echo $form->input('cities', array('default' => $venue['City'] > ['id'])); > > ...but that's clumsy compared to the "proper" solution. > > What am I missing to get this to work? > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<cake-php%[email protected]>For > more options, visit this group at > http://groups.google.com/group/cake-php?hl=en > Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] 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
