# Duplicating table data into another table

**URL:** <https://www.ruby-forum.com/t/duplicating-table-data-into-another-table/144079>\
**Category:** Rails\
**Created:** [July 25, 2008, 7:17am UTC](https://www.ruby-forum.com/t/duplicating-table-data-into-another-table/144079 "2008-07-25T07:17:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaily903](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@shaily903](https://www.ruby-forum.com/u/shaily903)\
**Post date:** [July 25, 2008, 7:17am UTC](https://www.ruby-forum.com/t/duplicating-table-data-into-another-table/144079/1 "2008-07-25T07:17:49Z")

</div>

Requirement: I am designing a Customer invoice system for a service  
company. company has some default rates across the company which is  
based on designation, experience level, qualification etc. These rates  
can be changed for a particular project. So project rates can overwrites  
the default rates

The way I am doing is:

1. create defaultrates tables which will be pre-populated with the  
default rate data
2. Project table contain information about project
3. projectrates table which contain exactly same fields as defaultrates  
table, except it will also contain foreign keys with project table (id)  
and defaultrates table(id).  
When the project is created projectrates table will be populated with  
all the data present in defaultrates table along with project\_id  
If user want to change the rates for a particular project, then  
projectrates table will be edited matching the particular project id

models:  
project  
has\_many :projectrates

projectrate

belongs\_to :project  
belongs\_to :defaultrate

defaultrate  
has\_many :projectrates

Questions

1. User will create the project, at back-end projectrates table should  
be populated with the data from defaultrates table along with  
project-id. how to do this??
2. show.rhtml , showing details of particular project should also show  
the details of project rates
3. edit.rhtml editing project, should also give user the functionality  
to edit project rates

Please it is important for me, so let me know how to do this?
