-
-
Save tubbo/009e77ac61f872ff363978a9301cbba0 to your computer and use it in GitHub Desktop.
Issue with polymorphic associations
This file contains hidden or 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
class Task < ActiveRecord::Base | |
has_one :notification_preference, as: :notifee | |
accepts_nested_attributes_for :notification_preference | |
end | |
class NotificationPreference < ActiveRecord::Base | |
belongs_to :notifee, polymorphic: true | |
end | |
# accepts_nested_attributes_for allows you to do this: | |
Task.find_or_initialize_by( | |
notification_preference_attributes: { | |
# attributes for the NP | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment