Inserting multiple records from one table (model) to another

Hello all, I've been getter better with Rails but I'm still just learning.

Here's what I have. I have one table (imports) and I read in a csv into this table. After doing some preliminary editing to each record I wish to insert all records into another table (projects) in one shot. I could create a new method in the projects controller and then call the "create", but doesn't that only insert one record?

I need a little clarity on this.

I know how to delete all records from a table. I wonder if it's as simple?

Thank you for any help.

JohnM

John Mcleod wrote:

Thanks for the quick reply.

But having two tables with identical structure is smelly. Why not just use a flag and a named_scope?

I'm not sure what you mean by this.

Then go look up named_scope -- or, in this case, default_scope.

Yes, both tables have the identical structure but my idea is too delete all data from the "import" table after the insert into the "projects" table. This way the user has a fresh table to get info from a csv file.

There's no reason to have a fresh table. Again, just flag records as appropriate.

Best,

Your right. I could not deal with the additional table.

Thanks for the insight.

John

Marnen Laibow-Koser wrote:

Ar Chron wrote:

Marnen Laibow-Koser wrote:

You could -- it's just poor design in most cases.

Most cases yes, but in some cases a parallel import table is not a bad thing.

If you put all your data into one table, then all the records going into that table have to pass all the model constraints immediately.

That's true, of course. But in that case, the tables don't have the same structure, so the smell doesn't apply.

From John's initial post, I read "after doing some preliminary editing" to imply that the records, as imported from CSV, may not satisfy all the constraints of the application.

It may be in his interest to keep these "dirty" records separate from the "clean" records so he does not have to relax any constraints on the mainstream application data,

You may be right. I hadn't thought of that from the initial description.

or complicate his existing model constraints by mixing a flag check into the middle of things.

default_scope is not complicated!

Ultimately, it'll be whatever works best for John.

Best,