Method: Sequel::Model::Associations::AssociationReflection#apply_dataset_changes

Defined in:
lib/sequel/model/associations.rb

#apply_dataset_changes(ds) ⇒ Object

Apply all non-instance specific changes to the given dataset and return it.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/sequel/model/associations.rb', line 84

def apply_dataset_changes(ds)
  ds = ds.with_extend(AssociationDatasetMethods).clone(:association_reflection => self)
  if exts = self[:reverse_extend]
    ds = ds.with_extend(*exts)
  end
  ds = ds.select(*select) if select
  if c = self[:conditions]
    ds = (c.is_a?(Array) && !Sequel.condition_specifier?(c)) ? ds.where(*c) : ds.where(c)
  end
  ds = ds.order(*self[:order]) if self[:order]
  ds = ds.limit(*self[:limit]) if self[:limit]
  ds = ds.limit(1).skip_limit_check if limit_to_single_row?
  ds = ds.eager(self[:eager]) if self[:eager]
  ds = ds.distinct if self[:distinct]
  ds
end