Skip to content
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

Improve form object attributes model referencing #50

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

pyromaniac
Copy link
Contributor

@pyromaniac pyromaniac commented Aug 7, 2024

Now it is possible to reference arbitrary attributes in model_map:

class Post::Update::ModelMap
  MAPPING = {
    %w[published_at] => Post, # a model can be passed but beware of circular dependencies, better use strings
    %w[title] => "Post", # or a model name - safer option
    %w[content] => "Post#body" # referencing different attribute is possible, useful for naming migration or translations
  }.freeze

  def call(path)
    MAPPING[path] # returns the mapping for a single path
  end
end

@pyromaniac pyromaniac force-pushed the attribute-reference-model branch from 723242c to 6329482 Compare August 7, 2024 03:43
@pyromaniac pyromaniac merged commit 22dadaf into main Aug 7, 2024
6 checks passed
@pyromaniac pyromaniac deleted the attribute-reference-model branch August 7, 2024 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant