【问题标题】:Field has a strange behavior if I don't use method:如果我不使用方法,字段会出现奇怪的行为:
【发布时间】:2019-06-13 14:30:52
【问题描述】:

我正在使用带有类版本基础的 graphql-ruby gem v 1.9.6。我正在使用 2 个模型。见下文。

模型 1:

class User < ApplicationRecord
  include EnsureUUID

  has_secure_password

  has_one :freelancer, dependent: :destroy ....

模型 2:

class Freelancer < ApplicationRecord
  include EnsureUUID

    belongs_to :user
    validates_uniqueness_of :user_id
end

如果我写:

field :from_user, UserType, null: true, method: :user

在我的 freelancer_type 声明中一切正常!

如果我写:

field :from_user, UserType, null: true

架构很糟糕!

我的问题是“方法::用户”在做什么?我在文档中找不到...

【问题讨论】:

    标签: graphql-ruby


    【解决方案1】:

    你可以这样做

    field :user, UserType, null: true
    

    这会起作用的!

    好的,方法是做什么的?

    它就像提供的字段名称的别名,这里的字段名称是from_user,我相信调用者(前端)知道/识别/想要成为。

    field :from_user, UserType, null: true, method: :user
    

    【讨论】:

      猜你喜欢
      • 2017-08-04
      • 2022-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      相关资源
      最近更新 更多