Skip to content
Browse files

non-numeric ids are no longer supported

  • Loading branch information...
1 parent af1c993 commit 442f0a18a8887a6dcc97b4933ebf338427ec4886 @aduffeck committed Sep 28, 2010
Showing with 9 additions and 12 deletions.
  1. +3 −0 Changelog.md
  2. +2 −2 README.md
  3. +2 −2 generators/has_alter_ego/templates/create_alter_egos.rb
  4. +1 −1 has_alter_ego.gemspec
  5. +1 −7 lib/has_alter_ego.rb
View
3 Changelog.md
@@ -1,3 +1,6 @@
+# 0.0.7 (2010-09-28)
+* non-numeric primary keys are no longer supported
+
# 0.0.6 (2010-09-28)
* Fixed a type mismatch problem with numeric ids
View
4 README.md
@@ -78,8 +78,8 @@ and you'd automagically have those objects available in your database.
Whenever the seed definition changes the objects in the database inherit the changes unless they have been overridden.
When a seed object was destroyed in the database it will not be added again.
-**Note:** If the table has a numeric primary key has_alter_ego reserves the first n IDs for seed objects (default=1000),
-so the next non-seed object will get the ID 1001.
+**Note:** has_alter_ego reserves the first n IDs for seed objects (default=1000), so the next non-seed object will get
+the ID 1001.
The number of reserved objects can be set with the optional *:reserved_space* parameter, e.g.
has_alter_ego :reserved_space => 5000
View
4 generators/has_alter_ego/templates/create_alter_egos.rb
@@ -1,7 +1,7 @@
class CreateAlterEgos < ActiveRecord::Migration
def self.up
create_table :alter_egos do |t|
- t.string :alter_ego_object_id
+ t.integer :alter_ego_object_id
t.string :alter_ego_object_type, :limit => 40
t.string :state
end
@@ -11,4 +11,4 @@ def self.up
def self.down
drop_table :alter_egos
end
-end
+end
View
2 has_alter_ego.gemspec
@@ -1,6 +1,6 @@
spec = Gem::Specification.new do |s|
s.name = "has_alter_ego"
- s.version = "0.0.6"
+ s.version = "0.0.7"
s.authors = ["André Duffeck"]
s.email = ["aduffeck@suse.de"]
s.homepage = "http://github.com/aduffeck/has_alter_ego"
View
8 lib/has_alter_ego.rb
@@ -14,7 +14,6 @@ def has_alter_ego opts = {}
has_one :alter_ego, :as => :alter_ego_object
alias_method :save_without_alter_ego, :save
alias_method :destroy_without_alter_ego, :destroy
- alias_method :alter_ego_with_type_fix, :alter_ego
send :include, InstanceMethods
reserve_space(opts[:reserved_space])
parse_yml
@@ -23,7 +22,6 @@ def has_alter_ego opts = {}
# Reserve the first n IDs for stubbed objects
def reserve_space space
- return unless self.columns_hash[self.primary_key].klass == Fixnum
return if self.last and self.last[self.primary_key] >= space
o = self.new
@@ -53,7 +51,7 @@ def parse_yml_for primary_key
end
else
# Check for destroyed alter_egos
- alter_ego = AlterEgo.find_by_alter_ego_object_id_and_alter_ego_object_type(primary_key.to_s, self.name)
+ alter_ego = AlterEgo.find_by_alter_ego_object_id_and_alter_ego_object_type(primary_key, self.name)
return if alter_ego.try(:state) == "destroyed"
db_object = self.new
@@ -97,10 +95,6 @@ def get_yml
end
module InstanceMethods
- def alter_ego
- return AlterEgo.find_by_alter_ego_object_id_and_alter_ego_object_type(self[self.class.primary_key].to_s, self.name)
- end
-
def has_alter_ego?
return self.alter_ego.present?
end

0 comments on commit 442f0a1

Please sign in to comment.
Something went wrong with that request. Please try again.