ok i got it
thx for the help Carlos.

The idea was right. Just couldnt get it for the simpl typo.
$this->First->Second->save(
....  :
I.E.
as a matter of fact one CAN call a (different) model method via the
Controller ...
Its only a matter of getting the data into the right format with the
(for beginners) queer syntax.
why doesnt anybody just simply tell that to all the poor newbies who
all start doing strange requestaction stuff ?
because its not obvious (to me only maybe ?? )  that the model method
in first can call the model method of the second !

so : in the FirstConrtoller :
  function add() {
              if (!empty($this->data)) {
                if ($this->First->save($this->data)) {

                        $defSec = array ('first_id'=>$this->First-
>id);
                        if ($this->First->Second->save($defSec))   //
dont know if create() is necessary b4
                        $this->Session->setFlash('Your First has been
saved, and the 'first of the second' created :) ');
                        $this->redirect(array('action' => 'index'));
                }
     }
     }


On 22 Jun., 19:56, Carlos Gonzalez Lavin <[email protected]>
wrote:
> Im a bit of a newbie to cake... but im guessing this could work after u save
> the First:
>
> $new_thing = array('Second' => array('first_id' => $this->First->id));
> $this->Second->save($new_thing);
> 2009/6/19 lefty <[email protected]>
>
>
>
> > how to automatically create() a "thingy" :)  in another model  ?
>
> > Say you have 2 model classes, 'first' & 'second', where the first
> > hasmany of the second.
> > BUT the first has to have at least one of the second - right from the
> > start !
> > How do you implement that ?
>
> > maybe can you add that somehow using as a basis the following code -
> > as simple as possible! :):)  ??  :
>
> > class First extends AppModel {
> >    var $name = 'First';
> >    var $hasmany = array('Second');
> > }
> > class second extends AppModel {
> >    var $name = 'Second';
> >    var $belongsto = array('First');
> > }
>
> > class FirstsController extends AppController {
>
> >        var $name = 'Firsts';
>
> >        function add() {
> >                if (!empty($this->data)) {
> >                        if ($this->First->save($this->data)) {
> >                        $this->Session->setFlash('Your First has been saved.
> > and the 'first
> > of the second' created :) ');
> >                        $this->redirect(array('action' => 'index'));
> >                        }
> >                }
> >        }
>
> > class SecondController .....
> > naturally each where they belong.
> > many thx
--~--~---------~--~----~------------~-------~--~----~
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