You could simply add a unique index on the database table of the SocialMedia model. Also you can add a validation:
validates_uniqueness_of :facebook_id
And in your User model you would test for presence and existence:
validate_presence_of :social_media_id
validate :social_profile_exists
protected
def social_profile_exists
errors.add(:social_media_id, "does not exist") unless SocialProfile.exists?(social_media_id)
end
Also maybe this would already work:
validates_associated :social_media
should ensure that the associated record itself is valid.