I have a Invite model, which has n + m attributes (location, timing etc.). When an invite is accepted, an Event object is created with n attributes copied from Invite model and k attributes of its own. I want to avoid duplication of n attributes.
How should I model this relationship in Rails?
Thank you.
Don’t think about the attributes, think about the objects and what they model (represent) in the real world. Also think about the life-cycle of the objects
Just because there is an overlap doesn’t mean that you want to eliminate it.
If you really want, you could say that every Event
belongs_toan Invite. (And thenattributes are stored only in the owning Invite model.)But before you do this, ensure with business logic that Invites are never changed once they reach the
acceptedstate.Added Another reason to duplicate the
nattributes: Suppose those attributes are later changed for the actual event–you’d want the attributes to be in the Event model. If you had one set of data for the Invite and the Event, then you’d be saying that those attributes are fixed from the time the Invite was entered.But that may well not match with the real world. And if you do change the values, then you’d lose the information of what the values originally were when the invite was entered.