Forum: Ruby on Rails ActiveRecord Constraints

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.
Perry S. (Guest)
on 2009-04-25 07:16
A plugin to easily add constraints into a PostgreSQL database.  I think
it would be easy to add other database engines to it assuming they
implement constraints.

The GIT repository is here:

http://github.com/pedz/activerecord_constraints

The rdoc is here:

http://pedz.github.com/activerecord_constraints

A small snippet from the readme:

Unique Constraint:

    class CreateFoos < ActiveRecord::Migration
      def self.up
        create_table :foos do |t|
          # name will have a "unique" constraint
          t.string :name, :null => false, :unique => true
        end
      end
    end

Trivial foreign key constraint:

    class CreateFoos < ActiveRecord::Migration
      def self.up
        create_table :foos do |t|
          # bar_id will now be a foreign key constraint column id in
table bar
          t.integer :bar_id, :null => false, :reference => true
        end
      end
    end
This topic is locked and can not be replied to.