Skip to content

Commit

Permalink
Remove ActiveRecordShards::Model.not_sharded
Browse files Browse the repository at this point in the history
  • Loading branch information
bquorning authored and jacobat committed Oct 12, 2017
1 parent 8a04334 commit a1a1f97
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 15 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ basically connections inherit configuration from the parent configuration file.
## Usage

Normally you have some models that live on a shared database, and you might need to query this data in order to know what shard to switch to.
All the models that live on the shared database must be marked as not\_sharded:
All the models that live on the sharded database must inherit from ActiveRecordShards::ShardedModel:

class Account < ActiveRecord::Base
not_sharded

has_many :projects
end

class Project < ActiveRecord::Base
class Project < ActiveRecordShards::ShardedModel
belongs_to :account
end

Expand Down
2 changes: 0 additions & 2 deletions lib/active_record_shards/default_slave_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ def model.on_slave_by_default?
left_reflection.klass.on_slave_by_default?
end

# also transfer the sharded-ness of the left table to the join model
model.not_sharded unless model.left_reflection.klass.is_sharded?
model
end
end
Expand Down
7 changes: 0 additions & 7 deletions lib/active_record_shards/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

module ActiveRecordShards
module Model
def not_sharded
if self != ActiveRecord::Base && self != base_class
raise "You should only call not_sharded on direct descendants of ActiveRecord::Base"
end
self.sharded = false
end

def is_sharded? # rubocop:disable Naming/PredicateName
self <= ActiveRecordShards::ShardedModel
end
Expand Down
2 changes: 0 additions & 2 deletions lib/active_record_shards/patches-5-0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@


ActiveRecord::Associations::Builder::HasAndBelongsToMany.include(ActiveRecordShards::DefaultSlavePatches::Rails41HasAndBelongsToManyBuilderExtension)

ActiveRecord::InternalMetadata.not_sharded

0 comments on commit a1a1f97

Please sign in to comment.