Module: ActiveScaffold::Tableless::Association

Defined in:
lib/active_scaffold/tableless.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



45
46
47
48
# File 'lib/active_scaffold/tableless.rb', line 45

def self.included(base)
  base.alias_method_chain :association_scope, :tableless
  base.alias_method_chain :target_scope, :tableless
end

Instance Method Details

#association_scope_with_tablelessObject



50
51
52
53
# File 'lib/active_scaffold/tableless.rb', line 50

def association_scope_with_tableless
  @association_scope ||= overrided_association_scope if klass < ActiveScaffold::Tableless
  association_scope_without_tableless
end

#overrided_association_scopeObject



55
56
57
58
59
60
61
# File 'lib/active_scaffold/tableless.rb', line 55

def overrided_association_scope
  if AssociationScope.respond_to?(:scope) # rails >= 4.1
    AssociationScope.scope(self, klass.connection)
  else # rails < 4.1
    AssociationScope.new(self).scope
  end
end

#target_scope_with_tablelessObject



63
64
65
66
67
68
69
# File 'lib/active_scaffold/tableless.rb', line 63

def target_scope_with_tableless
  target_scope_without_tableless.tap do |scope|
    if klass < ActiveScaffold::Tableless
      class << scope; include RelationExtension; end
    end
  end
end