module Clear::View

Overview

A view is like a read-only model. It has columns and relations It is automatically updated on migration by the migration manager

class MyView
  define <<-SQL
    SELECT * FROM users, other_views
  SQL

  depends_of OtherViews
end

Included Modules

Defined in:

clear/views/view.cr

Class Method Summary

Macro Summary

Instance methods inherited from module Clear::Model::HasColumns

[](x) : Clear::SQL::Any [], []?(x) : Clear::SQL::Any []?, reset(h : Hash(String, _))
reset(h : Hash(Symbol, _))
reset(**t : **T) forall T
reset
, set(h : Hash(String, _))
set(h : Hash(Symbol, _))
set(**t : **T) forall T
set
, to_h(full = false) to_h, update_h update_h

Class Method Detail

def self.define(x) #

[View source]
def self.depends_of(x : Class(T)) forall T #

[View source]

Macro Detail

macro scope(name, &block) #

A scope allow you to filter in a very human way a set of data.

Usage:

 scope("admin"){ where({role: "admin"}) }

for example, instead of writing:

  User.query.where{ (role == "admin") & (active == true) }

You can write:

  User.admin.active

Scope can be used for other purpose than just filter (e.g. ordering), but I would not recommend it.


[View source]