This Gem lets you easily integrate propertybase_id into your ActiveRecord model.
Add this line to your application's Gemfile:
gem "activerecord-propertybase_id"
And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord-propertybase_id
This ActiveRecord extension lets you use the Propertybase ID as a primary key in Rails.
The Propertybase ID is stored via the char(15)
data type (currently only tested on SQLite and PostgreSQL). You can also use the cusom migration type propertybase_id
.
Note: As Rails doesn't really support changing the type of the primary key in the migration. You need to work around a little bit. You need to disable the ID for a sepcific table and then add it as
class CreateTeams < ActiveRecord::Migration
def change
create_table :teams, id: false do |t|
t.propertybase_id :id, primary_key: true
t.string :name
t.timestamps null: false
end
end
end
You are now all set to use the Propertybase ID as the primary key of your table.
To make sure the ID is generated, you need to include the ActiveRecord::PropertybaseId
module:
class Team < ActiveRecord::Base
include ActiveRecord::PropertybaseId
end
The PropertybaseId need the object type as input. By default the object type will be inferred by the model name (currently only Team and User working), but you override it by specifying propertybase_object
class CustomizedUser < ActiveRecord::Base
include ActiveRecord::PropertybaseId
propertybase_object :user
end
Currently this gem only has been tested on PostgreSQL and SQLite and Rails version 4.2
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Heavily inspired by activeuuid.
- Fork it ( https://github.com/[my-github-username]/activerecord-propertybase_id/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request