I think this might work alright:

$data = $this->Location->find(
        'all',
        array(
                'conditions' => array(
                        'Location.id' => array(1,2,3,4)
                ),
                'recursive' => -1
        )
);

/* there's probably an elegant way to do this
 */
$data['Destination'] = $data['Location'];
unset($data['Location']);

$this->Destination->set($data);
$this->Destination->save();


... except that I suppose you'd have to remove the id fields first.
And you can't just set the 'fields' param for find() without it as
Cake will always (AFAIK) return the id. Perhaps you'd need to loop
through $data and assign each Location to another array, sans id.


On Wed, Aug 12, 2009 at 4:30 PM, paulos nikolo<[email protected]> wrote:
> Ok i get it.i had that idea on my mind.Now if i want to copy rows with the
> id 1,2,3,4... in locations table to destinations table i should do something
> like that?
> $this->Destination-=$this->Location;
> $this->Destination->save($this->data) ??
>
> I mean what's the appropriate query to database to implement this?
>
> 2009/8/12 brian <[email protected]>
>>
>> So the locations data is not kept? I think what I'd do is not bother
>> with a relation between the two models but use both models in the
>> locations_controller:
>>
>> var $uses = array('Location', 'Destination');
>>
>> Then you could do $this->Destination->etc.
>>
>> On Wed, Aug 12, 2009 at 2:45 PM, paulos nikolo<[email protected]>
>> wrote:
>> > Ty Brian for you reply.I have 2 models destination,location and 2
>> > controllers destinations and locations_controller.I dont have set a
>> > relation
>> > yet between them (i wasn't sure if it is necessary),but here is the
>> > idea.The
>> > initial data are saved in locations_controller,which contain some search
>> > data depend on user criteria.When the user find the search result he
>> > wants
>> > then i want to take these data from location table to be saved in
>> > destinations table.The data have the format like
>> >
>> > id,
>> > latitude,
>> > longtitude,
>> > countrycode,
>> > countryName
>> > etc
>> >
>> >
>> >
>> > 2009/8/12 brian <[email protected]>
>> >>
>> >> Which controller are you working with? Do you have both Location &
>> >> Destination models? How are they associated? What fields/columns do
>> >> they have?
>> >>
>> >> If you set up the $data correctly, you should be able to do, eg:
>> >>
>> >> $this->Location->Destination->set($data);
>> >> $this->Location->Destination->save();
>> >>
>> >>
>> >> On Wed, Aug 12, 2009 at 5:50 AM, Paulos23<[email protected]>
>> >> wrote:
>> >> >
>> >> > Hi ppl,
>> >> > I have a problem with my app.In particular i have a
>> >> > locations_controller where i receive some xml data ,which i parse
>> >> > them
>> >> > and save them in the locations table.The locations table usage is for
>> >> > cache reasons so i use a 2nd table destinations to save final choices
>> >> > of user.How can i get the data from locations table to destinations
>> >> > table in a smart way?
>> >> >
>> >> > Any help would be nice!
>> >> > Thx Paulos
>> >> > >
>> >> >
>> >>
>> >>
>> >
>> >
>> > >
>> >
>>
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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