Permalink
Browse files

Added support for models that declare a :has_one association

  • Loading branch information...
1 parent da25ecc commit b4e97ebe9066b4f81604f869a3aa7d4580e45ccc @ErwinM ErwinM committed Nov 20, 2011
Showing with 19 additions and 3 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −1 lib/acts_as_tenant/model_extensions.rb
  3. +1 −1 lib/acts_as_tenant/version.rb
  4. +12 −1 spec/model_extensions_spec.rb
View
@@ -1,3 +1,8 @@
+0.2.3
+-----
+* Added support for models that declare a has_one relationships, these would error out in the previous versions.
+
+
0.2.2
-----
* Enhancements
@@ -69,7 +69,7 @@ def self.is_scoped_by_tenant?
# we can't do this for polymorphic associations so we
# exempt them
reflect_on_all_associations.each do |a|
- unless a == reflection || a.macro == :has_many || a.options[:polymorphic]
+ unless a == reflection || a.macro == :has_many || a.macro == :has_one || a.options[:polymorphic]
# check if the association is aliasing another class, if so
# find the unaliased class name
association_class = a.options[:class_name].nil? ? a.name.to_s.classify.constantize : a.options[:class_name].constantize
@@ -1,3 +1,3 @@
module ActsAsTenant
- VERSION = "0.2.2"
+ VERSION = "0.2.3"
end
@@ -11,6 +11,12 @@
t.column :account_id, :integer
end
+ create_table :managers, :force => true do |t|
+ t.column :name, :string
+ t.column :project_id, :integer
+ t.column :account_id, :integer
+ end
+
create_table :tasks, :force => true do |t|
t.column :name, :string
t.column :account_id, :integer
@@ -39,12 +45,18 @@ class Account < ActiveRecord::Base
end
class Project < ActiveRecord::Base
+ has_one :manager
has_many :tasks
acts_as_tenant :account
validates_uniqueness_to_tenant :name
end
+class Manager < ActiveRecord::Base
+ belongs_to :project
+ acts_as_tenant :account
+end
+
class Task < ActiveRecord::Base
belongs_to :project
default_scope :conditions => { :completed => nil }, :order => "name"
@@ -202,6 +214,5 @@ class SubTask < ActiveRecord::Base
describe "It should be possible to use aliased associations" do
it { @sub_task = SubTask.create(:name => 'foo').valid?.should == true }
end
-
end

0 comments on commit b4e97eb

Please sign in to comment.