Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Model.sti_key, for easily setting up single table inheritance
Model.sti_key is a simple helper method. It doesn't add any new functionality, it just calls some existing methods to make it easy to set up STI quickly and correctly. It is only useful if you have a single string column in your table that contains the name of the class you would like to use. Model.sti_key should only be called in the parent class, not in the subclasses. The two things it does are: 1) Call dataset.set_model with a hash that results in a valid ruby class for any key. If there are problems using the string (like an empty string or NULL), it uses the class that called sti_key. 2) Add a before_create hook that sets the name of the sti_key column to the class name, so that when it is loaded from the database, you get the same class back. Example: class Artist < Sequel::Model sti_key :kind end
- Loading branch information
1 parent
80aed3a
commit cc7bbe8
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters