Skip to content

Type inheritance: How to inherit a set of fields derived from variable field name #3926

Answered by nimmolo
nimmolo asked this question in Q&A
Discussion options

You must be logged in to vote

Ah! Of course, it's an Interface i want. So much easier than i thought!

module Types::Models
  class UserType < Types::BaseObject
    implements Types::ImageUrls
module Types::ImageUrls
  include Types::BaseInterface
  description "Fields generating urls from image_id, thumb_image_id, etc"

  field :img_src_thumb, String, null: true
  field :img_src_sm, String, null: true
  field :img_src_med, String, null: true
  field :img_src_lg, String, null: true
  field :img_src_huge, String, null: true
  field :img_src_full, String, null: true

  def db_image_id
    case object
    when ::User
      object.image_id
    when ::Image
      object.id
    when ::Observation, ::GlossaryTerm
      object.t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nimmolo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant