@@ -1393,7 +1393,7 @@ class PostResource < JSONAPI::Resource
13931393
13941394 has_one :author , class_name : 'Person'
13951395 has_one :section
1396- has_many :tags , acts_as_set : true , inverse_relationship : :posts , eager_load_on_include : false
1396+ has_many :tags , acts_as_set : true , inverse_relationship : :posts
13971397 has_many :comments , acts_as_set : false , inverse_relationship : :post
13981398
13991399 # Not needed - just for testing
@@ -1917,16 +1917,7 @@ class AuthorResource < JSONAPI::Resource
19171917 model_name 'Person'
19181918 attributes :name
19191919
1920- has_many :books , inverse_relationship : :authors , relation_name : -> ( options ) {
1921- book_admin = options [ :context ] [ :book_admin ] || options [ :context ] [ :current_user ] . try ( :book_admin )
1922-
1923- if book_admin
1924- :books
1925- else
1926- :not_banned_books
1927- end
1928- }
1929-
1920+ has_many :books
19301921 has_many :book_comments
19311922 end
19321923
@@ -1966,6 +1957,9 @@ class BookResource < JSONAPI::Resource
19661957 }
19671958
19681959 filter :banned , apply : :apply_filter_banned
1960+ filter :title , apply : -> ( records , value , options ) {
1961+ records . where ( 'books.title LIKE ?' , "#{ value [ 0 ] } %" )
1962+ }
19691963
19701964 class << self
19711965 def books
@@ -1977,10 +1971,9 @@ def not_banned_books
19771971 end
19781972
19791973 def records ( options = { } )
1980- context = options [ :context ]
1981- current_user = context ? context [ :current_user ] : nil
1974+ current_user = options . dig ( :context , :current_user )
19821975
1983- records = _model_class . all
1976+ records = super
19841977 # Hide the banned books from people who are not book admins
19851978 unless current_user && current_user . book_admin
19861979 records = records . where ( not_banned_books )
@@ -1989,8 +1982,7 @@ def records(options = {})
19891982 end
19901983
19911984 def apply_filter_banned ( records , value , options )
1992- context = options [ :context ]
1993- current_user = context ? context [ :current_user ] : nil
1985+ current_user = options . dig ( :context , :current_user )
19941986
19951987 # Only book admins might filter for banned books
19961988 if current_user && current_user . book_admin
@@ -2030,7 +2022,7 @@ def approved_comments(approved = true)
20302022 end
20312023
20322024 def records ( options = { } )
2033- current_user = options [ :context ] [ :current_user ]
2025+ current_user = options . dig ( :context , :current_user )
20342026 _model_class . for_user ( current_user )
20352027 end
20362028 end
@@ -2085,7 +2077,7 @@ class PostResource < JSONAPI::Resource
20852077
20862078 has_one :author , class_name : 'Person' , exclude_links : [ :self , "related" ]
20872079 has_one :section , exclude_links : [ :self , :related ]
2088- has_many :tags , acts_as_set : true , inverse_relationship : :posts , eager_load_on_include : false , exclude_links : :default
2080+ has_many :tags , acts_as_set : true , inverse_relationship : :posts , exclude_links : :default
20892081 has_many :comments , acts_as_set : false , inverse_relationship : :post , exclude_links : [ "self" , :related ]
20902082 end
20912083
0 commit comments