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



38
39
40
41
# File 'lib/active_scaffold/tableless.rb', line 38

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



43
44
45
46
# File 'lib/active_scaffold/tableless.rb', line 43

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

#overrided_association_scopeObject



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

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



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

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