@@ -1413,7 +1413,7 @@ class PostResource < JSONAPI::Resource
14131413
14141414 has_one :author , class_name : 'Person'
14151415 has_one :section
1416- has_many :tags , acts_as_set : true , inverse_relationship : :posts , eager_load_on_include : false
1416+ has_many :tags , acts_as_set : true , inverse_relationship : :posts
14171417 has_many :comments , acts_as_set : false , inverse_relationship : :post
14181418
14191419 # Not needed - just for testing
@@ -1932,16 +1932,7 @@ class AuthorResource < JSONAPI::Resource
19321932 model_name 'Person'
19331933 attributes :name
19341934
1935- has_many :books , inverse_relationship : :authors , relation_name : -> ( options ) {
1936- book_admin = options [ :context ] [ :book_admin ] || options [ :context ] [ :current_user ] . try ( :book_admin )
1937-
1938- if book_admin
1939- :books
1940- else
1941- :not_banned_books
1942- end
1943- }
1944-
1935+ has_many :books
19451936 has_many :book_comments
19461937 end
19471938
@@ -1981,6 +1972,9 @@ class BookResource < JSONAPI::Resource
19811972 }
19821973
19831974 filter :banned , apply : :apply_filter_banned
1975+ filter :title , apply : -> ( records , value , options ) {
1976+ records . where ( 'books.title LIKE ?' , "#{ value [ 0 ] } %" )
1977+ }
19841978
19851979 class << self
19861980 def books
@@ -1992,10 +1986,9 @@ def not_banned_books
19921986 end
19931987
19941988 def records ( options = { } )
1995- context = options [ :context ]
1996- current_user = context ? context [ :current_user ] : nil
1989+ current_user = options . dig ( :context , :current_user )
19971990
1998- records = _model_class . all
1991+ records = super
19991992 # Hide the banned books from people who are not book admins
20001993 unless current_user && current_user . book_admin
20011994 records = records . where ( not_banned_books )
@@ -2004,8 +1997,7 @@ def records(options = {})
20041997 end
20051998
20061999 def apply_filter_banned ( records , value , options )
2007- context = options [ :context ]
2008- current_user = context ? context [ :current_user ] : nil
2000+ current_user = options . dig ( :context , :current_user )
20092001
20102002 # Only book admins might filter for banned books
20112003 if current_user && current_user . book_admin
@@ -2045,7 +2037,7 @@ def approved_comments(approved = true)
20452037 end
20462038
20472039 def records ( options = { } )
2048- current_user = options [ :context ] [ :current_user ]
2040+ current_user = options . dig ( :context , :current_user )
20492041 _model_class . for_user ( current_user )
20502042 end
20512043 end
@@ -2100,7 +2092,7 @@ class PostResource < JSONAPI::Resource
21002092
21012093 has_one :author , class_name : 'Person' , exclude_links : [ :self , "related" ]
21022094 has_one :section , exclude_links : [ :self , :related ]
2103- has_many :tags , acts_as_set : true , inverse_relationship : :posts , eager_load_on_include : false , exclude_links : :default
2095+ has_many :tags , acts_as_set : true , inverse_relationship : :posts , exclude_links : :default
21042096 has_many :comments , acts_as_set : false , inverse_relationship : :post , exclude_links : [ "self" , :related ]
21052097 end
21062098
0 commit comments