# ActiveRecord - schema and relations between

**URL:** <https://www.ruby-forum.com/t/activerecord-schema-and-relations-between/148116>\
**Category:** Rails\
**Created:** [September 9, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/activerecord-schema-and-relations-between/148116 "2008-09-09T14:10:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [September 9, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/activerecord-schema-and-relations-between/148116/1 "2008-09-09T14:10:16Z")

</div>

Hi,

I have quite complex db schema created by ActiveRecord and every  
constraints/relations are defined only in ActiveRecord objects.

I am going to create db schema diagram like ERD etc.

Do you have any idea how to do it?

It is fine too if I could build constraints in db.

Maybe one of you created an appropriate rake?

Greets,  
Mirek

---

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [September 9, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/activerecord-schema-and-relations-between/148116/2 "2008-09-09T14:42:53Z")

</div>

If you want to add constraints in the DB, you can always use execute  
within your migrations…

execute “ALTER TABLE `projects` your SQL goes here, blah blah blah”

Just execute the appropriate SQL statements in the self.up and self.down  
methods.

---

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [September 10, 2008, 9:16am UTC](https://www.ruby-forum.com/t/activerecord-schema-and-relations-between/148116/3 "2008-09-10T09:16:07Z")

</div>

You are right. But it is quite difficult(get a lot of time) to create  
these migrations by yourself. I have 30 tables, so I am looking for  
rake etc. to generate it.

Do you have any idea?

---

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [September 10, 2008, 9:23am UTC](https://www.ruby-forum.com/t/activerecord-schema-and-relations-between/148116/4 "2008-09-10T09:23:45Z")

</div>

On 10 Sep 2008, at 08:15, Zirael wrote:

> You are right. But it is quite difficult(get a lot of time) to create  
> these migrations by yourself. I have 30 tables, so I am looking for  
> rake etc. to generate it.

Why do you want migrations if you’ve already got the schema? Rails  
will dump your schema to schema.rb. With appropriate plugins  
([http://agilewebdevelopment.com/plugins/search?search=redhillonrails](http://agilewebdevelopment.com/plugins/search?search=redhillonrails)  
) it should handle foreign keys as well.

Fred

---

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [September 11, 2008, 4:00pm UTC](https://www.ruby-forum.com/t/activerecord-schema-and-relations-between/148116/5 "2008-09-11T16:00:35Z")

</div>

Thx, that plugin let me save lot of time.

There is only problem with polymorphic relationship.
