@@ -1393,7 +1393,7 @@ class PostResource < JSONAPI::Resource
1393
1393
1394
1394
has_one :author , class_name : 'Person'
1395
1395
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
1397
1397
has_many :comments , acts_as_set : false , inverse_relationship : :post
1398
1398
1399
1399
# Not needed - just for testing
@@ -1917,16 +1917,7 @@ class AuthorResource < JSONAPI::Resource
1917
1917
model_name 'Person'
1918
1918
attributes :name
1919
1919
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
1930
1921
has_many :book_comments
1931
1922
end
1932
1923
@@ -1966,6 +1957,9 @@ class BookResource < JSONAPI::Resource
1966
1957
}
1967
1958
1968
1959
filter :banned , apply : :apply_filter_banned
1960
+ filter :title , apply : -> ( records , value , options ) {
1961
+ records . where ( 'books.title LIKE ?' , "#{ value [ 0 ] } %" )
1962
+ }
1969
1963
1970
1964
class << self
1971
1965
def books
@@ -1977,10 +1971,9 @@ def not_banned_books
1977
1971
end
1978
1972
1979
1973
def records ( options = { } )
1980
- context = options [ :context ]
1981
- current_user = context ? context [ :current_user ] : nil
1974
+ current_user = options . dig ( :context , :current_user )
1982
1975
1983
- records = _model_class . all
1976
+ records = super
1984
1977
# Hide the banned books from people who are not book admins
1985
1978
unless current_user && current_user . book_admin
1986
1979
records = records . where ( not_banned_books )
@@ -1989,8 +1982,7 @@ def records(options = {})
1989
1982
end
1990
1983
1991
1984
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 )
1994
1986
1995
1987
# Only book admins might filter for banned books
1996
1988
if current_user && current_user . book_admin
@@ -2030,7 +2022,7 @@ def approved_comments(approved = true)
2030
2022
end
2031
2023
2032
2024
def records ( options = { } )
2033
- current_user = options [ :context ] [ :current_user ]
2025
+ current_user = options . dig ( :context , :current_user )
2034
2026
_model_class . for_user ( current_user )
2035
2027
end
2036
2028
end
@@ -2085,7 +2077,7 @@ class PostResource < JSONAPI::Resource
2085
2077
2086
2078
has_one :author , class_name : 'Person' , exclude_links : [ :self , "related" ]
2087
2079
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
2089
2081
has_many :comments , acts_as_set : false , inverse_relationship : :post , exclude_links : [ "self" , :related ]
2090
2082
end
2091
2083
0 commit comments