Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Anuj Patel
    @patelanuj28
    Any one has seen this issue?
    benebrice
    @benebrice
    Did you change key_type default value?
    Anuj Patel
    @patelanuj28
    Nope, I haven't changed anything it is working with 0.9.0, so I am guessing it's regression with 0.10.4
    Benjamin Fleischer
    @bf4
    Yes. I even have a fa8ling
    Failing pr. Been broken for years
    Anuj Patel
    @patelanuj28
    Does 0.10.4 supports include on polymorphism property like include=image.taggable?
    Anuj Patel
    @patelanuj28
    After monkey patching find_related_polymorphic_fragments with following change relation_position = relation_positions[row[2].underscore.pluralize] and updating association in the model. It started working.
    benebrice
    @benebrice
    Hi ! Do you think an integration of Goldiloader could be a good idea? This might solve a lot of time on optimisation with nested relationships...
    Larry Gebhardt
    @lgebhardt
    @benebrice Interesting looking gem. I'll take a look and see if it might be useful.
    benebrice
    @benebrice
    @lgebhardt I've just discovered it myself and test it. Works wonderfully with nested association usual issue. I was not able to integrate it easily on 0.9 but I'm sure you'll know exactly where to add it. 👌🏻
    Vincent Smith
    @Vince-Smith

    Is it no longer possible to inherit from JSONAPI::ResourceController in 0.10.4 on rails 6.0? I'm working on an upgrade from rails 5.2, but I'm also experiencing the same problem if I create a new app following the docs. Whenever I make a request I get the error:

    #<NameError: uninitialized constant JSONAPI::ResourceController
    Did you mean?  JSONAPI::ResourceControllerMetal>

    Tried setting config.autoloader = :classic but that didn't change anything.

    I've been able to work around this by using:

    class MyController < ActionController::Base
      include JSONAPI::ActsAsResourceController
    end

    This is the only relevant commit that I've been able to find so far that might be causing this

    Thanks! (I'm on ruby 2.7.2)

    Harbir Gill
    @harbirg
    Question - When specifying include on a resource, the response will include all relationships in response even if they do not have data or valid links. For example, if I call GET /books?include=author and books has many authors and has many covers. Even though I did /books?include=author, it will show covers in the relationship object with links that are invalid and no data. Is it possible to tell jsonapi-resources to restrict the relationships to respond if include parameter is used? I saw this stackoverflow that will remove links for relationships that have empty data but it doesnt remove the unnecessary relationship objects from the response ( https://stackoverflow.com/questions/44136258/removing-links-using-jasonapi-resources-gem )
    10 replies
    Harbir Gill
    @harbirg
    @lgebhardt - Larry, can you help with the above question if there is an override that i can make to remove unnecessary relationship objects
    Larry Gebhardt
    @lgebhardt
    @harbirg I'll try to look into that soon.
    Artur
    @artur79
    is there any way of adding virtual attributes to the resource ? Or it has to be done via model ?
    Artur
    @artur79
    so the attribute which in can pass with POST, use it to set some real attribute in resource, but I dont need to return it in any response
    Julius-Rapp
    @Julius-Rapp
    @artur79 : You can add getter and setter to the Resource, and the Getter can return nil. Is that what you need?
    Artur
    @artur79
    @Julius-Rapp here's the example code, if I run it it still tries to save time_range_appointment_id in the model, which I don't want to do cuz that field does not exist
    class Api::V1::TagAssociationResource < JSONAPI::Resource
      model_name 'TagAssociation'
    
      attributes :tag_id, :tag_type_id, :taggable_id, :taggable_type, :time_range_appointment_id
    
      # def self.creatable_fields(_context)
      #   super - [:time_range_appointment_id]
      # end
    
      before_save do
        if !@model.taggable && @model.time_range_appointment_id.present?
          time_range = TimeRange.find_by(appointment_id: @model.time_range_appointment_id)
    
          @model.taggable = time_range
        end
      end
    end
    and when I uncomment creatable_fields class method I'm getting error:
    Response body: {"errors":[{"title":"Param not allowed","detail":"time_range_appointment_id is not allowed.","code":"105","status":"400"}]}
    Artur
    @artur79
    I can solve it using attr_accessor in the model but I don't want to spoil it because I need it only in the API
    Artur
    @artur79
    thanks @Julius-Rapp for pointing to the right direction, here's the working solution, not so straightforward but works :)
    class Api::V1::TagAssociationResource < JSONAPI::Resource
      model_name 'TagAssociation'
    
      attributes :tag_id, :tag_type_id, :taggable_id, :taggable_type, :time_range_appointment_id
    
      def time_range_appointment_id=(val)
        @time_range_appointment_id = val
      end
    
      def time_range_appointment_id
        nil
      end
    
      def self.fetchable_fields(_context)
        super - [:time_range_appointment_id]
      end
    
      before_save do
        if !@model.taggable && @time_range_appointment_id.present?
          time_range = TimeRange.find_by(appointment_id: @time_range_appointment_id)
    
          @model.taggable = time_range
        end
      end
    end
    Nicholas
    @wasabigeek_twitter

    Hi all! What would be the best way to define an attribute on each of a resource's records just before returning it? The use case is to mark resources as "recommended" on the fly. I've tried to override the records method as such:

      def self.records(options = {})
        objects = super
        # sets the attr_accessor `recommended = true` on the model
        Recommender.new(context[:current_team]).mark_recommended(objects)
        objects
      end

    This doesn't work though, the response still shows recommended: nil. From what I've dug so far we lose this attribute somewhere during resource_klass.sort_records in apply_request_settings_to_records of ActiveRelationResource

    7 replies
    Artur
    @artur79
    In addition to my solution for accessor, the only issue is that it returns time_range_appointment_id = nil in any response, any way to get rid of it ? I need only to set it to use in before save
    Artur
    @artur79
    I always thought that which attributes are returned is specified in definition and from there swagger.json is created, I don't have this field in response, just in POST params
    I'v also got set def self.fetchable_fields(_context) super - [:time_range_appointment_id] end
    Artur
    @artur79
    found id, my fault :) in distinction of creatable and updatable it should be instance method, not class one, so without "self"
    Harbir Gill
    @harbirg
    @lgebhardt - Larry, wondering if you had time to look at my question above. thanks
    2 replies
    Thomas Carr
    @thomasc-mww
    Does anyone have advice, or can point me in the direction of an example, for implementing asynchronous patch requests (i.e. returning a 202)? It's not clear to me how to override the default behavior of update requests when using jsonapi-resources. Thank you!
    7 replies
    Larry Gebhardt
    @lgebhardt
    @harbirg Harbir, I left a reply under your original question.
    Darius Kazemi
    @dariusk
    Hi, thanks for this great library -- I'm running into an issue where I set config.top_level_meta_record_count_key = :record_count, and I get a meta object at the top level with a record count, but it seems to return the full count of the model rather than the full count after filters. Is this as designed? Do I need to implement my own processor? I would think so except the processors documentation for v0.9 says that would be redundant, if I'm reading it right. (I'm using v0.10 but there are no docs for processors for that version)
    Larry Gebhardt
    @lgebhardt
    @dariusk That is not working as designed. You should get the count after filters. Are the filters working otherwise?
    12 replies
    Connor Handerhan
    @chanderhan
    Hi - I'm having trouble making a resource for a heterogeneous collection.
    I'd like to be able to query this type of resource with includes/filters/sorts, but I can't get the index to include the polymorphic relation.
    Maybe I'm missing something simple.
    jsonapi-resources 0.10.4
    See the reply under this for a bug report template.
    12 replies
    Paulo Fernandes
    @pernambucano
    Hi everyone, so sorry if this has been already answered, but I tried to look out for it with no success. Do we already have support for atomic operations? Thank you so much in advance!
    Larry Gebhardt
    @lgebhardt
    @pernambucano We do not currently have support for that extension. I did have a PR for a very early version of atomic operations, before JSON API supported extensions, but that hasn't been updated yet to match the new extension. It is in the plans, but I haven't made the time for it yet.
    Paulo Fernandes
    @pernambucano
    Thanks a lot for the quick response, @lgebhardt . Is there any other way I could use what it's already in the lib to sidepost/create related instances in one go? I guess the other way would be to move a little from jsonapi, and adapt my code to pass everything in one go.
    Anthony To
    @anthonyto
    Hello everybody. Is there a conventional way to select specific fields in a query instead of selecting *? Seems that the fields filter only alters the serialized output and doesn't propogate to the SQL. We need this so we only select indexed columns in a large table
    11 replies
    Martins Kruze
    @martinskruze

    Hello, hard working maintainers!
    I ran into some error (or was unable to find answer in documentation) - I work with quite complex project which uses Ruby on Rails, and our PG db tables are divided in schemas.

    When I request "index" for resource I get this error:
    Internal Server Error: ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: missing FROM-clause entry FOR TABLE "schema_name.table_name" POSITION: 8:

    SELECT "schema_name.table_name"."id" AS "schema_name.table_name_id",
           schema_name.table_name.id
    FROM "schema_name"."table_name"
    WHERE "schema_name"."table_name"."type" IN ('StiType')
    ORDER BY schema_name.table_name.id ASC

    Have I missed something in documentation, is db schemas unsupported, or is it a bug?

    3 replies