Alas. nothing change, valid author_id value is still inside array.

Analyzing authors select form appear like:
<select id="BookAuthorId" name="data[Book][author_id][]">

if I remove last [] on the fly(with Firebug), the insert happen
without problem cause (I suppose) author_id is no more
 [author_id] => Array
                (
                    [0] => 15
                )
but
[author_id] => 15

Ideas?

On 4 Ago, 20:58, cricket <[email protected]> wrote:
> On Wed, Aug 4, 2010 at 6:05 AM, Mariano C. <[email protected]> wrote:
> > I know, this is a stupid question but I don't know how resolve this, I
> > have read a lot of docs but still don't understand.
>
> > I'm trying to create a biblio service and map Books/Authors,
> > I have SQL table for authors:
>
> > CREATE TABLE `authors` (
> > `id` int( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
> > `name` varchar( 127 ) NOT NULL ,
> > `email` varchar( 127 ) NOT NULL ,
> > `website` varchar( 127 ) NOT NULL
> > );
>
> > and related model
> > <?php
> > class Author extends AppModel
> > {
> > var $name = 'Author';
> > var $hasMany = 'Book';
> > }
> > ?>
>
> > and table for Books (with foreing key for author):
> > CREATE TABLE `books` (
> > `id` int( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
> > `isbn` varchar( 13 ) NOT NULL ,
> > `title` varchar( 64 ) NOT NULL ,
> > `description` text NOT NULL ,
> > `author_id` int( 11 ) NOT NULL
> > )
>
> > and related model:
> > <?php
> > class Book extends AppModel
> > { var $name = 'Book';
> > var $belongsTo = 'Author';
> > }
> > ?>
>
> > It seems all ok, now I try to insert new book in DB (author will be
> > choose by a select form).
> > <?php
> > class BooksController extends AppController {
> >  var $name = 'Books';
> >  function add() {
> >     if (!empty($this->data)) {
> >        $this->Book->save($this->data);
> >     }
> >    $authors = $this->Book->Author->find('list');
> >    $this->set('authors', $authors);
> >   }
> > }
> > ?>
>
> > and add view:
> > <?php echo $form->create('Book');?>
> > <fieldset>
> > <legend>Add New Book</legend>
> > <?php
> > echo $form->input('isbn');
> > echo $form->input('title');
> > echo $form->input('description');
> > echo $form->input('author_id');
> > ?>
> > </fieldset>
> > <?php echo $form->end('Submit');?>
>
> echo $form->input('author_id', array('options' => $authors));

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

Reply via email to