Absinthe - Many to many assoc with index table

Yeah the query was different from the one in the readme. I should have shared my repo right away instead of trying to give a continuity of the original discussion in this thread (i.e how to resolve a many-to-many assoc PLUS how to resolve an additional field from the index table, like inserted_at)… Sorry for the confusion, please just look at my repo and forget my posts in this thread, the problem should be clear enough.

couple of things:

  • repo query works fine if you add the field to the absinthe type schema as I indicated above
  • You didn’t add Timex as a dependency so I used string instead of timestamp as the type on the field
  • if you’re looking for help, its a lot easier to do that from a repo if you can point at a testcase that can be run without having to figure out what data needs to be created

repo query works fine if you add the field to the absinthe type schema as I indicated above

I didn’t manage, here’s the workaround I figured:

object :place do
    field :id, :id
    field :city, :string
    field :department, :string
    field :latitude, :float
    field :longitude, :float
    field :title, :string
    field :users, list_of(:user), resolve: assoc(:users)
    field :user_places, list_of(:user_place), resolve: assoc(:users)
  end

I guess I can be content with that, even if it’d have been better not to have to query user_places separately like so:

{
  places {
    id
    city
    department
    latitude
    longitude
    title
    users {
      id
      email
    }
    user_places {
      id
      inserted_at
    }
  }
}

if you’re looking for help, its a lot easier to do that from a repo if you can point at a testcase that can be run without having to figure out what data needs to be created

Forgive me I’m a total beginner with backend, so I’m not aware of this practice, nor do I know how to make such a testcase. I am aware I asked for help the wrong way, I’ll do better next time !

I sent you a PR so you could see what I mean.

Ah, now I see what you’re doing—your association on the Place schema is incorrect. I’ve also included that in the PR so you can see the issue.

1 Like