by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Adam Robertson
    @arcreative
    i have a method on my model that returns a relation, but can't be included with JR because it's not a real association
    Alex Oliveira
    @kurko
    Hi everyone. I'm trying to debug a weird issue. I have a relationship, and although I'm using always_include_linkage_data: true, the relationship's data is not present in the relationships key of the parent resource. I'm running byebug throughout the gem's code, and it looks like relationship_data is always empty in https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/resource_serializer.rb#L264. I'm not sure I'm missing something. My resources are pretty standard. Does anyone have any debugging tips?
    Alex Oliveira
    @kurko
    Can't make resource linkage work ;(
    Scott González
    @scottgonzalez
    @kurko Do you have the relationship defined in the resource?
    Alex Oliveira
    @kurko
    Yes. Simplest relationship you can imagine. Tried all sorts of things, joining the relationship in records_for_populate (e.g includes). Had byebug spread across the gem, relationships related variables/state are always empty. I decided to punt on this and just let it return links. I'll get back to it when I'm about to deliver the API as to not get blocked.
    Alex Oliveira
    @kurko
    @Julius-Rapp apologies I didn't respond. I didn't see your message.
    Benjamin Fleischer
    @bf4
    @kurko we're still on 0.9 but I'd be surprised if the vanilla case didn't work. (when we tried to upgrade to 0.10 soon after stable came out our blocker was that we treat 'calculated' resources as posts/create and the way that was being handled in JR had changed in a way I was unable to resolve at the time. ) do you have a gist or something to share? routes set up with the jsonapi_resources macro, controllers exists, resources exist? it's possible the docs are wrong (seemed at the time at the 0.10 docs were just copied from 0.9 even when wrong)
    @arcreative yes, either just override the instance getter and/or make sure you turn off any eager loading flags on the relationship, like eager_load_on_include: false, and probably exclude_links: :default. I'm assuming there's an unrouted controller for the relation and an abstract resource for the model
    Julius-Rapp
    @Julius-Rapp
    @kurko no worries. If you are still interested in overriding top-level meta then you may have a look at cerebris/jsonapi-resources#1067 .
    sandric
    @sandric
    Hi there. I have a question mb somebody have answer to - how can you call jsonapi resource from code or repl? I mean I have fairly complicated resource with bunch of filters, which have_many and belongs to other resources, that also have queries. And I need to somehow get active record result of calling request to that resource with filters passed as json params. Is it possible somehow?
    Gordon Potter
    @eccegordo
    Has anyone done any range filters like: gte x AND lte y. Curious about the filter syntax for that. And how does the range interact with the pagination feature?
    Scott González
    @scottgonzalez
    @eccegordo You have to create custom filters for that.
    So the syntax is up to you.
    I suggest something like x=>5
    Gordon Potter
    @eccegordo
    I guess the one thing I still kind of hazy on is managing potentially mutually exclusive filters? Can I do this server side? For example if one particular filter is present then ignore other specific filters... I guess I can just not pass the to API. Or conversely if a certain filter is present then also ensure that an additional filter is specified with default value if not provided by client. Wondering how the filter control flow can work. If that makes sense.
    Scott González
    @scottgonzalez
    You really shouldn’t ignore filters. If anything, you should raise an error if there are incompatible filters.
    I’ve always handled that in the controller.
    Cezar Halmagean
    @chalmagean_twitter
    can you create a resource that doesn't belong to a model? I basically need an endpoint for a collection of key/value pairs
    Scott González
    @scottgonzalez
    @chalmagean_twitter Every resource is backed by a model, but it doesn’t have to be an ActiveRecord model.
    Cezar Halmagean
    @chalmagean_twitter
    @scottgonzalez what kind of model do you mean?
    Scott González
    @scottgonzalez
    A model can literally be any class, but it’s going to have to implement the relevant methods that the resource uses. For example, save, validate, the getters and setters, etc.
    Cezar Halmagean
    @chalmagean_twitter
    @scottgonzalez is there a list of what is needed? It doesn't work with any class, nor does it work by using any of ActiveModel modules.
    Julius-Rapp
    @Julius-Rapp
    @chalmagean_twitter I have just found some test code that may be related to your needs: https://github.com/cerebris/jsonapi-resources/blob/5517f173a55ba2960c4f0852e8c51f8dd76194cc/test/fixtures/active_record.rb#L1545
    Kevin Coleman
    @KevinColemanInc

    (Sorry if this is better as a github issue) but I am trying to upgrade from 0.9 to 0.10 and the way records are loaded broke my registration process.

    Currently, I have a user_resource that overrides "#records" so that only the current user (via auth context) can query the user records

    # UserResource.rb
      def self.records(options = {})
        if options.dig(:context, :current_user)
          User.none
        else
          _model_class.where(id: user&.id)
        end
      end

    When a resource is created in 0.10, we persist the resource to the db and then try to re-load it by calling UserResource#records. But since this is a registration request and there is no current user, the records returns nothing and thus the json response returns {"data": null}, even though the user was successfully created.

    Any ideas how to fix this? For this particular modal, I could look at patching in the current_user to the context, but in general, how would you support a resource the user can only write to, but not (typically) read from? E.g. you create a log record and the api returns a created_at, but the user can't fetch that record again

    code flow:
    In the processor, we call find_fragments after creating a resource:
    https://github.com/cerebris/jsonapi-resources/blob/5517f173a55ba2960c4f0852e8c51f8dd76194cc/lib/jsonapi/processor.rb#L404
    find_fragments calls resource.records to reload the model that was created based on the _primary_id
    https://github.com/cerebris/jsonapi-resources/blob/5517f173a55ba2960c4f0852e8c51f8dd76194cc/lib/jsonapi/active_relation_resource.rb#L107

    1. Am I doing this right?
    2. Why do we need to reload the object from the db that was just created?
    premptive thanks! to anyone who responds :)
    Edwin Liang
    @EdwinLiang_twitter
    @KevinColemanInc Are you trying to return the same record back after it was created?
    2 replies
    BilalAddam
    @BilalMAddam
    Hello, I'm having some difficulties performing multiple POST requests. When the database is empty, the first post request works just fine.However, When attempting to run many (database is not empty), I get <Too many primary objects for show excluded from capture: DSN not set Internal Server Error: Too many primary objects for show>. This exception is raised at line 62 in jsonapi/resource_serializer.rb. In fact, I tried to debug the code, one attempt was to comment the fail exception (awful I know :p). It seems to work (of course, the returned value is the first entry in the database which is not in sync with the one being created by the POST request). I would really like to know if I'm missing something or doing anything wrong. Thx in advance
    Larry Gebhardt
    @lgebhardt
    @BilalMAddam are you doing anything "special" in the controller code for these post requests?
    BilalAddam
    @BilalMAddam
    nothing special
    @lgebhardt the thing is, resource_set (argument for the function that raises this exception at line 62) contains all the table's rows (all entries). I've verified it by inspecting it. That's why, the function throws systematically this error if the len(entries) > =1.
    Larry Gebhardt
    @lgebhardt
    After a create call it should just be returning the recently created resource. Which version are you using?
    BilalAddam
    @BilalMAddam
    @lgebhardt <gem 'jsonapi-resources', '=0.10.2'>
    Larry Gebhardt
    @lgebhardt
    @BilalMAddam Somehow you're getting multiple models in the resource_set. After a create there's a find_resource_set call that uses the new id as the value for a filter on the primary key. Is it possible you added some custom logic to the id filter?
    BilalAddam
    @BilalMAddam
    @lgebhardt Indeed, that was the bug, I've overriden the apply_filter function and added some custom logic to it. Thank you very much for your support, you saved me a lot of time debugging it!
    Eric Gross
    @ericgross
    I am trying to upgrade from Rails 5 to Rails 6 and it is going well but it seems that there are no routes anymore from jsonapi-resources - is that a known issue?
    Larry Gebhardt
    @lgebhardt
    @ericgross the routes should still be working. Can you provide a bit more information? Which JR version? Anything special about your routes or setup?
    Eric Gross
    @ericgross

    @ericgross the routes should still be working. Can you provide a bit more information? Which JR version? Anything special about your routes or setup?

    @lgebhardt I am running JR 0.9.11 with Rails 6.0.3.2. I'm not doing anything special - I've got an api namespace and a v1 namespace inside that with a jsonapi_resource and some nested jsonapi_resources. The only route that doesn't seem to be working is jsonapi_resources :events, only: %i[create]and bundle exec rake routes | grep api_v1_events is empty

    Eric Gross
    @ericgross
    @lgebhardt do you have any more ideas? Not sure what to try next.
    Eric Gross
    @ericgross
    In general, how can i dig in to find out why a specified resources route isn't being added to the routing table?
    Eric Gross
    @ericgross
    The problem was that the resource was immutable!
    ahmadabdelhalim
    @ahmadabdelhalim
    Hey, guys!
    I'm trying to use json schema to validate the response. The problem I'm facing is that jsonapi-resource returns the following
    "id": "3", "type": "drivers", "links": { "self": "http://localhost:3000/api/admin/v1/drivers/3" },
    and links here is an object, so when I add that to json schema, I get the following error:
    JsonSchema::AggregateError:
       #: "object" is not a valid "links", must be a array.
    Arthur Alkmim
    @rockertux
    Good morning, everyone! Is it possible to strip the relationships and links fields from the serialized response in 0.9 or 0.10?
    I see there's a PR for that from 2016 which is not merged and from what I've read in the docs I can't see if it is possible or not. I couldn't find anything useful by skimming through the source code but I might be missing something
    Julius-Rapp
    @Julius-Rapp
    @rockertux do you know exclude_links from https://jsonapi-resources.com/v0.10/guide/resources.html#Options ?
    @rockertux relationships should be missing by default if the resource does not have any relationships defined. Alternatively, the client can use sparse fieldsets. Does that help?
    Arthur Alkmim
    @rockertux
    Hm, we do have some relationships defined but we're using them to access child fields
    I think I missed this exclude_links, thanks for pointing that!
    Arthur Alkmim
    @rockertux
    @Julius-Rapp thanks, I think I got riiight on track with that
    ManhND
    @manhnd.hebestorm_gitlab
    Hi everyone, today I added paranoia to soft-deleted, but when I tried to get index with scope with_deleted, every fields were blank