Class: INatGet::Data::Helper::Field::Has Private
- Inherits:
-
Scalar
- Object
- INatGet::Data::Helper::Field
- Scalar
- INatGet::Data::Helper::Field::Has
- Defined in:
- lib/inat-get/data/helpers/defs/has.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from INatGet::Data::Helper::Field
Instance Method Summary collapse
-
#initialize(helper, key, association, extra = nil) ⇒ Has
constructor
private
A new instance of Has.
- #to_sequel(value) ⇒ Object private
Methods inherited from Scalar
Methods inherited from INatGet::Data::Helper::Field
Constructor Details
#initialize(helper, key, association, extra = nil) ⇒ Has
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Has.
7 8 9 10 11 |
# File 'lib/inat-get/data/helpers/defs/has.rb', line 7 def initialize helper, key, association, extra = nil super helper, key, Boolean @association = association @extra = extra end |
Instance Method Details
#to_sequel(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/inat-get/data/helpers/defs/has.rb', line 13 def to_sequel(value) reflection = @helper.manager.model.association_reflection(@association) main_table = @helper.manager.model.table_name if reflection[:type] == :many_to_many join_table = reflection[:join_table] left_key = reflection[:left_key] right_key = reflection[:right_key] right_table = reflection.associated_class.table_name query = @helper.manager.model.db[join_table] .join(right_table, :id => right_key) .where(Sequel[join_table][left_key] => Sequel[main_table][:id]) query = query.where(@extra) if @extra condition = query.exists else associated_class = reflection.associated_class foreign_key = reflection[:key] query = associated_class.where(foreign_key => Sequel[main_table][:id]) query = query.where(@extra) if @extra condition = query.exists end value ? condition : Sequel.~(condition) end |