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