Re: I need conceptual help transferring my existing data

2009-06-03 Thread brian

On Wed, Jun 3, 2009 at 1:15 AM, Ian R  wrote:
>
>
> On Jun 2, 7:45 pm, brian  wrote:
>> Model::create() doesn't actually create a new DB record, it just sets
>> up the model instance. You have to use save() for that.
>>
>> What i've done in the past when moving an existing project to Cake is
>> to create a (non-cake) script that simply moves the data from one
>> database to the other, the latter DB being designed according to Cake
>> conventions.
>
>
>  Ha!  Well, that had been my original plan, and then I thought "oh,
> this is probably really easy the Cake way, and a good learning
> experience".  Well, maybe I'll go running back.  Thanks, Brian, and if
> anybody has any other thoughts, I'd be pleased to hear them!

That was what I had thought, also. Though one would have to select the
original data using query(), given the tables are unlikely to follow
Cake's conventions.

That wouldn't be such a big deal except that I also never did figure
out how to select from 2 separate DBs. Of course, I could have just
copied the old DB tables to the new, then added the Cake tables to it
and create methods to copy the data between them. But I had a few old
tables that had exactly the name I need to satisfy Cake conventions.
And then I'd still have to go in and clean out the old tables. So, in
the end, it seemed *much* simpler to just write an old-school script
to take care of this.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: I need conceptual help transferring my existing data

2009-06-02 Thread Ian R


On Jun 2, 7:45 pm, brian  wrote:
> Model::create() doesn't actually create a new DB record, it just sets
> up the model instance. You have to use save() for that.
>
> What i've done in the past when moving an existing project to Cake is
> to create a (non-cake) script that simply moves the data from one
> database to the other, the latter DB being designed according to Cake
> conventions.


 Ha!  Well, that had been my original plan, and then I thought "oh,
this is probably really easy the Cake way, and a good learning
experience".  Well, maybe I'll go running back.  Thanks, Brian, and if
anybody has any other thoughts, I'd be pleased to hear them!

Ian

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: I need conceptual help transferring my existing data

2009-06-02 Thread brian

Model::create() doesn't actually create a new DB record, it just sets
up the model instance. You have to use save() for that.

What i've done in the past when moving an existing project to Cake is
to create a (non-cake) script that simply moves the data from one
database to the other, the latter DB being designed according to Cake
conventions.

On Tue, Jun 2, 2009 at 6:15 PM, Ian R  wrote:
>
>
> So hello there.
>
> I have a table of businesses (restaurants, etc.) in my old framework,
> and I'm trying to remake things with Cake (I'm catching on but still
> shaky) so I've set up 3 new tables to house the data which used to be
> all in this one "businesses" table: "writeups", "locations" and (of
> course) "tags".
>
> - Writeup hasMany Location
> - Location BelongsTo Writeup
> - Location HABTM Tag
>
> It all works quite well when I'm dealing with test data which I added
> through a modified scaffolding.  But now I'm working on transferring
> my existing data to this new set-up.  I'm haven't exhausted all of my
> experimentation muscle just yet, but I don't know quite what to look
> for in the archives, etc., and meanwhile projects are piling up while
> I beat my head against this... so...
>
> Can anyone suggest the best way to do this?  I have written code thus
> far which gets all the active businesses, groups those with multiple
> locations, and creates an array of tag_ids from the comma-separated
> "tags" field of the old table.  I had been thinking I could iterate
> through the "businesses" and do:
>
> - foreach distinct Business, create a new Writeup and populate it with
> my existing data
>   --foreach Business's location, create a new Location, populate it
> with the existing data and the writeup_id for the BelongsTo, and
> attach to that Location the array of appropriate Tags, and then save
> each Location
> - and then save the Writeup, having attached the array of Locations
>
> So, here's a question:  I had figured that upon calling Writeup::create
> (), I would have returned to me an array for the new Writeup which
> included the id.  That doesn't seem to be the case.  Do I need to save
> the record before I start (so I can call GetInsertID or something) and
> then I can update it afterwards?
>
> Also, can I save at the end, having built my $data array just using id
> references for the associated fields, i.e.:
>
> data['Writeup']['name'] = 'Test Name'
> data['Writeup']['copy'] = 'A bunch of words and whatever'
> data['Location'][0]['id'] = 23
> data['Location'][1]['id'] = 27
> data['Location'][2]['id'] = 34
>
> Something like that?  I'd really appreciate some help, or a push
> towards something I could read on the subject.
>
> Thanks so much (in advance!)
> Ian
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---