Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Created April 13, 2017 19:50
Show Gist options
  • Save laspluviosillas/95c66a2976cd3fa52688c9e5a2f69e7b to your computer and use it in GitHub Desktop.
Save laspluviosillas/95c66a2976cd3fa52688c9e5a2f69e7b to your computer and use it in GitHub Desktop.
Issue with polymorphic associations
class Task < ActiveRecord::Base
has_one :notification_preference, as: :notifee
end
class NotificationPreference < ActiveRecord::Base
belongs_to :notifee, polymorphic: true
end
# Code above keeps on looking for notifee_id on Task.
# The foreign keys are obviously in the NotificationPreference table (notifee_id and notifee_type)
# But I only want Task to have one associated notification preference.
# how do i do this?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment