# Hi there

**URL:** <https://www.ruby-forum.com/t/hi-there/135216>\
**Category:** Rails\
**Created:** [April 19, 2008, 9:11am UTC](https://www.ruby-forum.com/t/hi-there/135216 "2008-04-19T09:11:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 19, 2008, 9:11am UTC](https://www.ruby-forum.com/t/hi-there/135216/1 "2008-04-19T09:11:12Z")

</div>

Hi there

I subscribed to this mailint list this morning after days looking for  
the way to do it, so this is my first post.

My name is Miquel and I have been coding with ruby for a year and a  
half (using Qtruby bindings) and now I’m a rails newbie (I’m with it  
since a month ago). Now I’m coding an app and I’m trying to create  
(using migrations) a table which has a column named ‘id’ which is  
primary key but it’s not auto\_increment. The primary key db schema of  
this part is:

Table users: ‘id’ primary key auto\_increment.  
Table registered\_users: ‘id’ primary key.  
Table non\_registered\_users: ‘id’ primary key.

I migrated it using the execute command to create the table first and  
after using the add\_column command.

My question is…is there a way using rails migrations to create  
these three tables?

Thanks in advance.

Regards

–

Miquel (a.k.a. Ktalà a.k.a. Ton)  
Linux User #286784  
GPG Key : 4D91EF7F  
Debian GNU/Linux (Linux wolverine 2.6.23.1)

Welcome to the jungle, we got fun and games  
Guns n’ Roses

---

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 19, 2008, 9:20am UTC](https://www.ruby-forum.com/t/hi-there/135216/2 "2008-04-19T09:20:50Z")

</div>

class CreateManyTable \< ActiveRecord::Migration  
def self.up  
create\_table :first\_tables do |t|  
t.column :any\_column, :string  
end  
create\_table :second\_tables do |t|  
t.column :any\_column, :string  
end  
create\_table :third\_tables do |t|  
t.column :any\_column, :string  
end  
end

def self.down  
drop\_table :first\_tables  
drop\_table :second\_tables  
drop\_table :third\_tables  
end  
end

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 19, 2008, 10:10am UTC](https://www.ruby-forum.com/t/hi-there/135216/3 "2008-04-19T10:10:17Z")

</div>

Maybe I didn’t make myself clear (english problem maybe). The thing is  
that I want that the first table’s (first\_tables) id column is  
auto\_increment and not the second and the third one (second\_tables and  
third\_tables).

If this migration example the three tables will have a column named  
‘id’ which is integer, primary\_key and auto\_increment.

Regards

–

Miquel (a.k.a. Ktalà a.k.a. Ton)  
Linux User #286784  
GPG Key : 4D91EF7F  
Debian GNU/Linux (Linux wolverine 2.6.23.1)

Welcome to the jungle, we got fun and games  
Guns n’ Roses

On Sat, 19 Apr 2008 09:20:50 +0200

---

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 19, 2008, 11:54am UTC](https://www.ruby-forum.com/t/hi-there/135216/4 "2008-04-19T11:54:43Z")

</div>

On 19 Apr 2008, at 09:09, Miquel O. wrote:

> Maybe I didn’t make myself clear (english problem maybe). The thing is  
> that I want that the first table’s (first\_tables) id column is  
> auto\_increment and not the second and the third one (second\_tables and  
> third\_tables).
> 
> If this migration example the three tables will have a column named  
> ‘id’ which is integer, primary\_key and auto\_increment.

You can pass :id =\> false to create\_table to stop it creating the id  
column for you (you can then create it yourself with whatever options  
you want)

Fred

---

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 19, 2008, 11:52am UTC](https://www.ruby-forum.com/t/hi-there/135216/5 "2008-04-19T11:52:57Z")

</div>

Why would you want the ID column not to be auto\_increment?

On Rails you don’t necessarily code towards specific values on  
columns, you code towards objects and their properties.

And the table names you mentioned: users, registered\_users,  
non\_registered\_users suggest that you should have one user model with  
a column registered, type boolean (instead of three different models).  
Then, if you want to find all objects from that model which have the  
property registered as false, you do something like:

@users = Users.find(:all, :registered =\> true)

And note that I don’t use tables and columns to refer to data, I use  
models and properties. You should code in Rails from that  
perspective.

---

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 19, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/hi-there/135216/6 "2008-04-19T16:46:50Z")

</div>

Thanks Fred, it seems to be the right answer. I’m going to try it.

Regards,  
Miquel

On Sat, 19 Apr 2008 10:53:57 +0100  
Frederick C. wrote:

> > If this migration example the three tables will have a column named
> > 
> > > ```
> > > t.column :any_column, :string
> > > 
> > > ```
> > > 
> > > ## Reinhart [http://teapoci.blogspot.com](http://teapoci.blogspot.com)
> > > 
> > > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–

Miquel (a.k.a. Ktalà a.k.a. Ton)  
Linux User #286784  
GPG Key : 4D91EF7F  
Debian GNU/Linux (Linux wolverine 2.6.23.1)

Welcome to the jungle, we got fun and games  
Guns n’ Roses

---

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 19, 2008, 12:04pm UTC](https://www.ruby-forum.com/t/hi-there/135216/7 "2008-04-19T12:04:05Z")

</div>

Hi

Sometimes user’s stored data is different if a user is registered or  
not (maybe a registered user has email, login, password, etc and the  
non\_registered user only has the email). In this case you have two  
options.

The first one is add all the column in an only table inserting null  
values depending if its a non registered user, but I don’t like this  
way. The other option is a table called users and two tables, which has  
a relation 1:1 with the previous one called registered and  
non\_registered. The tables users has the common data which have  
registered and non\_registered and the different data is stored in the  
other two tables.

The column ‘id’ is common to the three tables but in table users is  
autonumeric and in the other two is not (because the id value is set  
by the first one and share with the others).

Hope this explains better.

Regards

–

Miquel (a.k.a. Ktalà a.k.a. Ton)  
Linux User #286784  
GPG Key : 4D91EF7F  
Debian GNU/Linux (Linux wolverine 2.6.23.1)

Welcome to the jungle, we got fun and games  
Guns n’ Roses

On Sat, 19 Apr 2008 02:52:08 -0700 (PDT)
