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

Allow proc default values that depend on other values #2195

Conversation

pedrocarmona
Copy link
Contributor

Add ability to set default values that depend on other values from a given record.

Example:
If slice belongs to cake with frostings, then allow to set frostings in cake slice by default.

class Slice < Sequel::Model
   many_to_one :cake
   plugin :defaults_setter
   
   def self.default_values
      {
        frosting: lambda { |slice| slice.cake&.frosting? },
      }
   end
 end
Cake.create(frosting: true)
Slice.new(cake_id: cake.id).frosting # => true

@jeremyevans
Copy link
Owner

Thanks for the patch! I'll test and merge later today.

@pedrocarmona
Copy link
Contributor Author

Thank you Jeremy 🙌

@jeremyevans jeremyevans merged commit 980c261 into jeremyevans:master Jul 25, 2024
16 checks passed
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.

2 participants