views:

14

answers:

1

Kind of hard to explain but I'm going to try: I have a model called Message, which represents a request for an email to be sent out, a model called Segment which is pulled from a third-party application using a MySQL view (and is read-only), and finally a User model. Segment and message both belong to a user.

The problem is that I need to display a list of Segments as a multiple select listbox on the form to create a new Message, and store that data since an email is generated to our marketing department and should display the segments the user wants their message sent to. There also needs to be a "default" value which represents the user's entire list (e.g. "All my contacts" with a default value). However, I can't write to the view (nor do I want to since it's pulling from a third party app).

Now I'm confused about how to go about constructing this. I could create a new model called MessageSegment that joins messages and segments, but this leaves the issue of how to deal with the default value, since it cannot be added to the base Segment model but has to remain a selectable option.

A: 

I think that the easiest way is to create join table for messages and segments (like you proposed) and add a column to message model 'send to all' or something simillar.

But if segments are from different application then it can change this table and then all your messages joins could be broken. Also if segments will change then 'sent to all' has a different meaning. So if you are sure that this application that feed segments table will not break segments-messages joins then if user choose 'sent to all' then you can make associations with all segments and not use additional column.

But if segments table could change then I would copy all data from segments table and associate it with message. I know it is redundant but it will be more safe.

Hope it helps.

klew