Method: Sequel::Model::ClassMethods#subset

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

#subset(name, *args, &block) ⇒ Object

Sets up a dataset method that returns a filtered dataset. Sometimes thought of as a scope, and like most dataset methods, they can be chained. For example:

Topic.subset(:joes, :username.like('%joe%'))
Topic.subset(:popular){num_posts > 100}
Topic.subset(:recent){created_on > Date.today - 7}

Allows you to do:

Topic.joes.recent.popular

to get topics with a username that includes joe that have more than 100 posts and were created less than 7 days ago.

Both the args given and the block are passed to Dataset#filter.

This method creates dataset methods that do not accept arguments. To create dataset methods that accept arguments, you should use define a method directly inside a #dataset_module block.



596
597
598
# File 'lib/sequel/model/base.rb', line 596

def subset(name, *args, &block)
  dataset_module.subset(name, *args, &block)
end