-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed9711a
commit 63cd64a
Showing
4 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class ActiveUserView < SQLView::Model | ||
materialized | ||
|
||
schema -> { User.where(age: 18..60) } | ||
|
||
extend_model_with do | ||
# sample how you can extend it, similar to regular AR model | ||
# | ||
# include SomeConcern | ||
# | ||
# belongs_to :user | ||
# has_many :posts | ||
# | ||
# scope :ordered, -> { order(:created_at) } | ||
# scope :by_role, ->(role) { where(role: role) } | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
test/dummy/db/migrate/20220215124409_create_active_user_view.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateActiveUserView < ActiveRecord::Migration[7.0] | ||
def up | ||
ActiveUserView.sql_view.up | ||
end | ||
|
||
def down | ||
ActiveUserView.sql_view.down | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters