Module: Torque::PostgreSQL::Relation::DistinctOn
- Included in:
- Torque::PostgreSQL::Relation
- Defined in:
- lib/torque/postgresql/relation/distinct_on.rb
Instance Attribute Summary collapse
-
#distinct_on_value ⇒ Object
Returns the value of attribute distinct_on_value.
Instance Method Summary collapse
-
#distinct_on(*value) ⇒ Object
Specifies whether the records should be unique or not by a given set of fields.
-
#distinct_on!(*value) ⇒ Object
Like #distinct_on, but modifies relation in place.
Instance Attribute Details
#distinct_on_value ⇒ Object
Returns the value of attribute distinct_on_value.
6 7 8 |
# File 'lib/torque/postgresql/relation/distinct_on.rb', line 6 def distinct_on_value @distinct_on_value end |
Instance Method Details
#distinct_on(*value) ⇒ Object
Specifies whether the records should be unique or not by a given set of fields. For example:
User.distinct_on(:name)
# Returns 1 record per distinct name
User.distinct_on(:name, :email)
# Returns 1 record per distinct name and email
User.distinct_on(false)
# You can also remove the uniqueness
19 20 21 |
# File 'lib/torque/postgresql/relation/distinct_on.rb', line 19 def distinct_on(*value) spawn.distinct_on!(*value) end |
#distinct_on!(*value) ⇒ Object
Like #distinct_on, but modifies relation in place.
24 25 26 27 |
# File 'lib/torque/postgresql/relation/distinct_on.rb', line 24 def distinct_on!(*value) self.distinct_on_value = value self end |