-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for custom foreign_key? #30
Comments
I'm not sure I understand. Absinthe.Ecto doesn't explicitly use the primary key, or any other key at all. It relies entirely on your Ecto associations. |
Thanks for getting back to me @benwilson512. I believe this was user error. I was attempting to handle associations from a database that started its life as Drupal; which has a mixture of unconventional primary keys and foreign keys. To simplify things, I created a test scenario that required custom foreign keys, and all went well (eerily well, actually). It looks something like this (loosely mimicking Facebook's Post Graph API): # ecto schema
schema "posts" do
field :message, :string
belongs_to :from, User, foreign_key: :from_user_id
belongs_to :to, User, foreign_key: :to_user_id
timestamps()
end # graphql types
object :user do
field :id, :id
field :email, :string
field :first_name, :string
field :last_name, :string
field :wall, list_of(:post), resolve: assoc(:wall)
end
object :post do
field :id, :id
field :message, :string
field :from, :user, resolve: assoc(:from)
end # graphql query
{
user (id: 1) {
wall {
message
from {
firstName
lastName
}
}
}
} This results in two queries (one for posts, and one for users). Awesome! |
Cool! |
@bjunc hello, I'm trying something similar, how did you define your "users" schema? |
It appears that the association is stitching together the field name and custom
@primary_key
, but ignoringforeign_key
.The text was updated successfully, but these errors were encountered: