Class: Recurso::Queries::Relation
- Inherits:
-
Object
- Object
- Recurso::Queries::Relation
- Defined in:
- lib/recurso/queries/relation.rb
Instance Method Summary collapse
-
#initialize(identity, resource, relation_name, all_columns: true, action: :view, include_actions: []) ⇒ Relation
constructor
A new instance of Relation.
- #resources ⇒ Object
Constructor Details
#initialize(identity, resource, relation_name, all_columns: true, action: :view, include_actions: []) ⇒ Relation
Returns a new instance of Relation.
5 6 7 8 9 10 11 12 |
# File 'lib/recurso/queries/relation.rb', line 5 def initialize(identity, resource, relation_name, all_columns: true, action: :view, include_actions: []) @identity = identity @resource = resource @relation = resource.send(relation_name) @all_columns = all_columns @include_actions = (include_actions + Array(action)).uniq @action = action end |
Instance Method Details
#resources ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/recurso/queries/relation.rb', line 14 def resources @relation .select("#{@relation.table_name}.#{@all_columns ? :"*" : :id}") .select(*@include_actions.map { |action| "included.can_#{action}"}) .joins(" INNER JOIN (#{}) included ON #{@relation.table_name}.id = included.id AND included.can_#{@action} = 1 ") end |