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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fb67821b5f3db39fea1ef9dd96883c4341cdede
4
- data.tar.gz: d7ebdd268fb277a8c6f07ca499874d6088a3e2a3
3
+ metadata.gz: d9131d7932eed7001aeb99adbd26c658008c2c26
4
+ data.tar.gz: 5758efa739cb76c7872b67b162d202544c083b2c
5
5
  SHA512:
6
- metadata.gz: ab5bec3a4805c440a0a52b64c62bb1822333169426703c60526bc901df682d6fc2c6c53d98bfb6a9bcd02b396692618dbf762ab487c7a7f8f1b1634831164421
7
- data.tar.gz: 73e08bf142091102411f8dca9a293c24abadb9cbcf39f3ace5b62d7c0d0d46e0f8f98ddaa43f280c2de399205f7439e351e7009f2cf27a73341a628f18dcc95a
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.21~)
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.21~)
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.name ASC
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 if table_name.present? and !ActiveRecord::Base.connection.tables.include?(table_name)
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!("#{table_name}#{table_name.present? ? '.' : ''}#{column_name} #{order}")
100
+ order!("`#{table_name}`.`#{column_name}` #{order}")
100
101
  end
101
102
  end
102
103
  end
@@ -1,3 +1,3 @@
1
1
  module Baseapi
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.22"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baseapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moriyuki Arakawa