Skip to content

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
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