Hi I would like to know what do you think is better in my situation. I am developing an application with Rails 4.0.2, ActiveRecord and Devise.I have a users table with about 100,000 Users and about 5% has sales (5000). Marketing wants to add a feature to send the User details to Facebook (For ads campaign) once we sell something to that user. The user need to be sent just once to facebook. For that I want to create a new table user_flags with has_one flag (zero or one) Meaning User Model has a has_one: :user_flags and UserFlags will have a belongs_to to :user. The UserFlags Model will have attributes like sent_to_facebook, facebook_sent_success.I can think of 4 ways to achieve this:Create a data migration for all the Users and create a record UserFlags for each one and then add after_create callback on the User Model and create a UserFlags.Pros: I can use user.user_flags.sent_to_facebook freely without checking that user.user_flags is not nil first. Cons: a lot of users that does not need that record will have itAdd a method user_flags_or_build that will return user_flags if it is not nil otherwise it will create a new instance and return it user_flags  || build_user_flags Pros: Only create records for users with sales.other developers may use user_flags.sent_to_facebook without checking if it is nil firstLike option 2 but instead of creating a new function override user_flags function like this super || build_user_flags. Pros: Other developers can use user.user_flags.sent_to_facebook freely. Cons: extra check even if it is not needed. May cause problem with the way ActiveRecord natively handle association.Add after_initialize callback after_initialize :build_user_flags. Pros: can call user.user_flags.sent_to_facebook freely. Cons: sometimes you do not need the user_flags association when created the new User but it is created anywayI am looking for the best practice to do this in term of good OOP design and doing it the Rails way. Performance is not a big issue. Feel free to offer other ideas and insightsSome reference I have been using:https://stackoverflow.com/questions/3808782/rails-best-practice-how-to-create-dependent-has-one-relationshttps://stackoverflow.com/questions/3802179/how-to-autobuild-an-associated-polymorphic-activerecord-object-in-rails-3
Rails auto build has_on association on get
object oriented design;ruby on rails;activerecord