-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor logic of keywords into a view-based model.
- Loading branch information
1 parent
e0e50ec
commit bc0b268
Showing
10 changed files
with
78 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
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,15 @@ | ||
# This is a view-based model | ||
# The view is defined in migration file: 20131116163151_create_dataset_tags_view.rb | ||
# More info about view-based model can be found in Chapter 11 in book 'Enterprise Rails'. | ||
|
||
class DatasetTag < ActiveRecord::Base | ||
belongs_to :dataset | ||
belongs_to :tag, class_name: 'ActsAsTaggableOn::Tag' | ||
|
||
def self.tag_counts | ||
ActsAsTaggableOn::Tag.joins('left join dataset_tags on tags.id = dataset_tags.tag_id') | ||
.select('tags.*, count(dataset_id) as count') | ||
.group('tags.id') | ||
.order('lower(tags.name)') | ||
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
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
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
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,23 @@ | ||
class CreateDatasetTagsView < ActiveRecord::Migration | ||
def up | ||
execute <<-SQL | ||
CREATE OR REPLACE view dataset_tags AS | ||
( | ||
select taggable_id as dataset_id, tag_id | ||
from taggings | ||
where taggable_type = 'Dataset' | ||
union | ||
select distinct d.dataset_id, g.tag_id | ||
from taggings g join datacolumns d | ||
on g.taggable_id = d.id | ||
where g.taggable_type = 'Datacolumn' | ||
); | ||
SQL | ||
end | ||
|
||
def down | ||
execute <<-SQL | ||
drop view dataset_tags; | ||
SQL | ||
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
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