ActionController::ForceSSL
class has been removed. This throws an error from the gem here: https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/resource_controller_metal.rb#L8 . I don't see anything active to get ahead of that removal
Hi guys!
I'm migrating from 0.9 to 0.10 and I'm switching from records_for
to apply_join
and I've some issues with my id key (which is uuid
and not id
).
It seems that JSONAPI::PrimaryResourceIdTree
(on JSONAPI::Processor#find_resource_id_tree
still use id
instead of uuid
which leads to an error on JSONAPI::ResourceSet#populate!
with @resource_klasses[resource_klass][resource.id]
where resource.id
is a correct uuid
but key of the hash resulting of find_resource_id_tree
is still id
(and not uuid
).
Does anyone else have had this issue before?
Thank you in advance !
def get_relation
verified_filters = resource_klass.verify_filters(params[:filters], context)
resource_klass._model_class.where(verified_filters)
end
def get_sorted_relation
sort_criteria = params.fetch(:sort_criteria, [])
order_options = resource_klass.send(:construct_order_options, sort_criteria)
resource_klass.send(:sort_records, get_relation, order_options, context)
end
def get_paginated_relation
paginator = params[:paginator]
get_sorted_relation.limit(paginator.limit).offset(paginator.offset)
end
def self.sortable_fields(_context)
super + %i[category_natural]
end
sort :category_natural, apply: -> (records, direction, _context) {
categories_mapped = Account::ACCOUNT_CATEGORIES.map(&Account.connection.method(:quote))
subcategories_mapped = Account::ACCOUNT_SUBCATEGORIES.map(&Account.connection.method(:quote))
records
.order("COALESCE(array_position(array[#{categories_mapped.join(',') }], accounts.account_category::text ), 100) #{direction}")
.order("COALESCE(array_position(array[#{subcategories_mapped.join(',')}], accounts.account_subcategory::text), 100) #{direction}")
}
sort
, it should automatically add that to the sorted fields hash instead of having to add it explicitly. That's just QoL though.
Hey, I have a very odd need... I need to be able to commit a record to the database during say an update, and even if the update overall fails I need that record saved. Basically I need my own manual transaction control in a situation.
A good example: I need to create a payment record, commit it, then do a bunch of updates with db locks to ensure no double payment, then commit an update to that payment record that it completed.
Is there anything that allows for that inside the resource?
My current plan is a custom method in my controller and control the transaction manually.
Thread.new do
ActiveRecord::Base.connection_pool.with_connection do
...
end
end
parameter name: 'filter[user.grade.level]', in: :query, type: :integer, required: false
filter :'user.grade.level', apply: ->(records, value, _options) do
scope = records.joins(user: :grade)
level = value[0]
if level.is_a?(Hash) && lge = level['ge']
scope.where('grades.level >= ?', lge.to_i)
else
scope.where(grades: { level: level.to_i })
end
end
has some bugs in the code and was trying to pass hash in the spec as param value, here's final working version
filter :'user.grade.level', apply: ->(records, value, _options) do
scope = records.joins(user: :grade)
level = value[0]
if level.respond_to?(:to_h) && level.has_key?('ge')
scope.where('grades.level >= ?', level['ge'].to_i)
else
scope.where(grades: { level: level.to_i })
end
end
and in spec param is like let(:'filter[user.grade.level]') { 4 }
or let(:'filter[user.grade.level][ge]') { 5 }
btw, need to mention that even if params are specified like
parameter name: 'filter[user.grade.level]', in: :query, type: :integer, required: false
parameter name: 'filter[user.grade.level][ge]', in: :query, type: :integer, required: false
a String is passed (e.g "5") not Integer
to_f
for timestamps makes sense, but would welcome other ideas.