baseapi 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/lib/baseapi/active_record/relation_extension.rb +4 -3
- data/lib/baseapi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9131d7932eed7001aeb99adbd26c658008c2c26
|
4
|
+
data.tar.gz: 5758efa739cb76c7872b67b162d202544c083b2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b2d2a423c600e8d1dffd81206d816fa3916fa148b5367c609b9bbdf81ab6e7f4b45b9d65b72e69e553d928148d94f9abd982dfed164b5f52bf93ad0fb9b5064
|
7
|
+
data.tar.gz: 0ea3ff497b6bb26a6e39c03a2f421c9da822db8e3419c8a65dfa77d5f093cbb00c31d9e9978c5637e8f30b414b7a1673530c20058e0acf12579ebd8015976870
|
data/README.md
CHANGED
@@ -102,15 +102,15 @@ Specify the sorting order
|
|
102
102
|
GET /users.json?order=desc&orderby=name
|
103
103
|
SQL => SELECT DISTINCT `users`.* FROM `users` ORDER BY `users`.`name` DESC
|
104
104
|
|
105
|
-
Specify the multiple sorting order (v0.1.
|
105
|
+
Specify the multiple sorting order (v0.1.22~)
|
106
106
|
|
107
107
|
GET /users.json?order[]=desc&order[]=asc&orderby[]=name&orderby[]=company_id
|
108
|
-
SQL => SELECT DISTINCT `users`.* FROM `users` ORDER BY name DESC, company_id ASC
|
108
|
+
SQL => SELECT DISTINCT `users`.* FROM `users` ORDER BY `users`.`name` DESC, `users`.`company_id` ASC
|
109
109
|
|
110
|
-
Specify the association sorting order (v0.1.
|
110
|
+
Specify the association sorting order[^1] (v0.1.22~)
|
111
111
|
|
112
112
|
GET /users.json?order=asc&orderby=company.name
|
113
|
-
SQL => SELECT DISTINCT `users`.* FROM `users` ...JOIN... ORDER BY companies
|
113
|
+
SQL => SELECT DISTINCT `users`.* FROM `users` ...JOIN... ORDER BY `companies`.`name` ASC
|
114
114
|
|
115
115
|
Specify the name
|
116
116
|
|
@@ -510,6 +510,11 @@ It will return an error content
|
|
510
510
|
[jbuilder details here](https://github.com/rails/jbuilder)
|
511
511
|
|
512
512
|
|
513
|
+
## TODO
|
514
|
+
|
515
|
+
[^1]: orderby associated with foreign_key
|
516
|
+
*1 : orderby associated with foreign_key
|
517
|
+
|
513
518
|
## Development
|
514
519
|
|
515
520
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec baseapi` to use the code located in this directory, ignoring other installed copies of this gem.
|
@@ -79,14 +79,15 @@ module ActiveRecordRelationExtension
|
|
79
79
|
# dot notation example: company.name
|
80
80
|
joins_tables = orderby.split(".")
|
81
81
|
column_name = joins_tables.pop
|
82
|
-
table_name = joins_tables.count > 0 ? joins_tables.last.pluralize.underscore :
|
82
|
+
table_name = joins_tables.count > 0 ? joins_tables.last.pluralize.underscore : self.model.to_s.pluralize.underscore
|
83
83
|
# joins_tables exists check
|
84
84
|
joins_tables.each do |table|
|
85
85
|
next if !ActiveRecord::Base.connection.tables.include?(table.pluralize.underscore)
|
86
86
|
end
|
87
|
+
# check
|
87
88
|
if table_name.present?
|
88
89
|
# table exists check
|
89
|
-
next
|
90
|
+
next !ActiveRecord::Base.connection.tables.include?(table_name)
|
90
91
|
# column_name exists check
|
91
92
|
next if !table_name.camelize.singularize.constantize.column_names.include?(column_name)
|
92
93
|
else
|
@@ -96,7 +97,7 @@ module ActiveRecordRelationExtension
|
|
96
97
|
# joins
|
97
98
|
joins_array!(joins_tables)
|
98
99
|
# order
|
99
|
-
order!("
|
100
|
+
order!("`#{table_name}`.`#{column_name}` #{order}")
|
100
101
|
end
|
101
102
|
end
|
102
103
|
end
|
data/lib/baseapi/version.rb
CHANGED