Forum: Ruby on Rails Without the magical id column in table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Af3cecc8af253b5acd3c09c5b67c0074?d=identicon&s=25 Valentino Lun (on9west)
on 2009-02-17 11:10
Dear all

In rails, the are some magical column such as id, created_at, updated_at
can make things easier.

However, within my organization, due to whatever reason, the data type
identity is not allowed to use. So, the magical id column cannot be used
in my rails project. I know that there is some actions rely on the like
http://localhost:3000/controller/action/123, where 123 is the :id...and
in edit_path(:id), It seems that without the id column I cannot perform
these actions.. Am I right?

Should I change other web framework in my project (but I love rails
^_^)? Or any workaround available in rails if my table without the id
column? Is it really a matter for the CRUD action without id column?

Please give me some advices.

Thank you.

Valentino
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-17 11:48
(Received via mailing list)
On 17 Feb 2009, at 10:10, Valentino Lun wrote:

> in my rails project. I know that there is some actions rely on the
> like
> http://localhost:3000/controller/action/123, where 123 is
> the :id...and
> in edit_path(:id), It seems that without the id column I cannot
> perform
> these actions.. Am I right?
>
Rails assumes very much that there is a primary key (as in a single
column that uniquely identifies rows i don't think it actually cares
whether it is labelled a primary key in the database), you don't have
to call it id though (see set_primary_key). I'm not sure what would
happen if the primary wasn't auto increment (or associated with a
sequence etc.) but you could give it a go.

Fred
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2009-02-17 16:51
(Received via mailing list)
You can use a UUID instead... never used it myself though.

google "rails uuid"



On Feb 17, 5:10 am, Valentino Lun <rails-mailing-l...@andreas-s.net>
10f7e00c1c5c60e2173995eb16f4ffc7?d=identicon&s=25 pepe (Guest)
on 2009-02-19 05:22
(Received via mailing list)
Hi there,

I have worked with legacy databases that had no 'id' column but had a
different column as primary key. You only need to add the following
code to your models:

  self.primary_key = 'your_primary_key_column_here'

I hope this helps.

Pepe

On Feb 17, 5:10 am, Valentino Lun <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.