On Sun, Apr 3, 2011 at 11:01 PM, DavidJ <[email protected]> wrote:

>
> Now, I've surfed around the web for information about how to use
> custom ids or other primary key columns in Rails, but have only found
> confusion (ignoring people who ask why and/or say not to do it).
> Examples given seem to differ (perhaps due to changes before Rails 3?)
> and I can't get any of the ideas to work.
>
> For example, supposing I wish to use UUIDs for primary keys.  I've
> tried variations on:
>
> class CreateItems < ActiveRecord::Migration
>  def self.up
>    create_table :items, {:id => false} do |t|
>      t.string :id, :null => false, :limit => 36, :primary => true
>
>      t.timestamps
>    end
>
>  end
>
>  def self.down
>    drop_table :items
>  end
> end
>
> However, the :primary doesn't seem to work (perhaps is invalid) and
> the table generated doesn't have a primary key.  I can use add_index
> to add a :unique index, but it isn't primary.  Obviously, I'll need
> some hooks to generate the UUIDs - I've delved into that part.
>
> So, can Rails really handle this in a clean way and have scaffolding
> work etc?  How?  Can someone kindly clue me into what I need in the
> migration, model class and anywhere else?  I'd prefer to avoid DB-
> specific SQL execution (while I'm testing this on MySQL, that
> obviously isn't a distributed scalable technology so I'll be using a
> distributed store ultimately).
> I'd also like some tables to have natural (domain specific) primary
> key values, a related though perhaps separate issue (and less
> critical).
>
> I've achieved similar on another project using Grails by writing a JPA
> implementation.  I'm really hoping Rails can do this without having
> the source hacked.
>
> Any help or pointers are greatly appreciated.
>
>
For now you are going to have to execute some sort of SQL to set
non-standard Rails primary keys. The below article covers all the steps and
gems you will need to make setting primary keys other than the auto
increment integer work. The SQL call outlined in this article is pretty
standard and you should not have issues moving it from database to database.

http://roninonrails.blogspot.com/2008/06/using-non-standard-primary-keys-with.html

On the issue of scaling, Rails has come a long way since it's early
inception and the issues Twitter had. Rails can scale, just don't be afraid
to do some work to make it happen. Here is a 21 screen cast series from
Gregg Pollack and New Relic that discuss and show you how to scale Rails.

http://railslab.newrelic.com/scaling-rails

B.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to