# Reflect table changes in models

**URL:** <https://discuss.rubyonrails.org/t/reflect-table-changes-in-models/1088>\
**Category:** rubyonrails-talk\
**Created:** [September 5, 2006, 11:49am UTC](https://discuss.rubyonrails.org/t/reflect-table-changes-in-models/1088 "2006-09-05T11:49:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bart\_Braem](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@Bart\_Braem](https://discuss.rubyonrails.org/u/Bart_Braem)\
**Post date:** [September 5, 2006, 11:49am UTC](https://discuss.rubyonrails.org/t/reflect-table-changes-in-models/1088/1 "2006-09-05T11:49:49Z")

</div>

Hello,

I am adapting an existing system and I want to change some tables. I want to turn a column into a reference to a new table. What's the best way to do this? I guess migrations but how do I make the new models then? I am pretty new to rails so if you could provide me with the generator commands to that would be great. Of course online references are fine too!

Regards, Bart

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [September 5, 2006, 1:01pm UTC](https://discuss.rubyonrails.org/t/reflect-table-changes-in-models/1088/2 "2006-09-05T13:01:02Z")

</div>

Hi Bart,

Bart Braem wrote:

> how do I make the new models then?

It seems unlikely, for someone undertaking a change to an app's data model, that what you're looking for is this basic, but just in case... To generate a new model for a table:

ruby script\generate model ModelName

Also, don't forget the Rails convention is that the ModelName is the singular of the table's name.

hth, Bill

---

<div class="post-metadata">

**Author:** ![Stephen\_Bartholomew2](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@Stephen\_Bartholomew2](https://discuss.rubyonrails.org/u/Stephen_Bartholomew2)\
**Post date:** [September 5, 2006, 1:42pm UTC](https://discuss.rubyonrails.org/t/reflect-table-changes-in-models/1088/3 "2006-09-05T13:42:08Z")

</div>

> I am adapting an existing system and I want to change some tables. I want to turn a column into a reference to a new table. What's the best way to do this?

If you have existing models, they will pick up any changes to the database.

For example, if you a 'products' table with an associated 'Product' model:

# assign price product.price = 5

Then you decide to change 'price' to 'sale\_price' and generate/run a migration to do so. You can then just use the new column without changing your model:

# assign price product.sale\_price = 5

Hope that helps and sorry if it's not quite what you meant :0)

Steve

---

<div class="post-metadata">

**Author:** ![Bart\_Braem](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@Bart\_Braem](https://discuss.rubyonrails.org/u/Bart_Braem)\
**Post date:** [September 5, 2006, 3:22pm UTC](https://discuss.rubyonrails.org/t/reflect-table-changes-in-models/1088/4 "2006-09-05T15:22:17Z")

</div>

Stephen Bartholomew wrote:

> > I am adapting an existing system and I want to change some tables. I want to turn a column into a reference to a new table. What's the best way to do this?
> 
> If you have existing models, they will pick up any changes to the database.
> 
> For example, if you a 'products' table with an associated 'Product' model:
> 
> # assign price product.price = 5
> 
> Then you decide to change 'price' to 'sale\_price' and generate/run a migration to do so. You can then just use the new column without changing your model:
> 
> # assign price product.sale\_price = 5
> 
> Hope that helps and sorry if it's not quite what you meant :0)

It's not really what I meant. I'll give an example with the product table. I currently have price, but say that I want to be a row in another table pricetag. That row would have columns like tagcolor, currency and value. (As an example, I don't need currency conversion!) So how do I make that conversion to a reference to an external table? If I generate the table with migrations it seems to fail...

Regards, Bart
