# Dynamic ActiveRecord Associations

**URL:** <https://www.ruby-forum.com/t/dynamic-activerecord-associations/92412>\
**Category:** Rails\
**Created:** [April 19, 2007, 9:06am UTC](https://www.ruby-forum.com/t/dynamic-activerecord-associations/92412 "2007-04-19T09:06:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cidol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@cidol](https://www.ruby-forum.com/u/cidol)\
**Post date:** [April 19, 2007, 9:06am UTC](https://www.ruby-forum.com/t/dynamic-activerecord-associations/92412/1 "2007-04-19T09:06:54Z")

</div>

I’m trying to make some dynamic AR associations.

The clearest way I can think of to give an idea of what I’m looking to  
do  
is in a simple bit of code . ( with some schema-changing pseudo code )

# add column “some\_class\_id” to table “other\_class”

SomeClass.has\_many( :other\_class )  
OtherClass.belongs\_to( :some\_class )

# drop column “some\_class\_id” from table “other\_class”

SomeClass.no\_longer\_has\_many( :other\_class )  
OtherClass.no\_longer\_belong\_to( :some\_class )

Some solutions I’m thinking of now:

1. doing some sort of object serialization to sequester the changes  
made to the class and then using that cache to rip them out later
2. just re-creating the class without the association I’ve removed.

Just looking for some feedback/ideas or even a simple solution if it  
already  
exists before I dig into this.

Thank you,  
Collin T Miller
