I have a newsletter system that contains a multitude of different
newsletters. In this case three but the system allows the user to
add more. Every user can be subscribed to any amount of given
newsletters. So what I did was I created a user model, newsletter
model, and subscription model.
The subscription model belongs to one user and one newsletter.
However, I’m not quite sure what to do after that. Is this the
proper way to perform this type of relationship or is it something
where I would give the newsletter model a has_and_belongs_to_many
users relationship? I’m not quite sure how to go about it. Any advice?
way to perform this type of relationship or is it something where I
would give the newsletter model a has_and_belongs_to_many users
relationship? I’m not quite sure how to go about it. Any advice?
In Rails 1.0, you’re probably doing all you can, but this sounds like a
perfect case for :through relationships in Edge Rails.
On Thu, Feb 09, 2006 at 10:39:36PM -0700, Jim J. wrote:
proper way to perform this type of relationship or is it something
where I would give the newsletter model a has_and_belongs_to_many
users relationship? I’m not quite sure how to go about it. Any advice?
Because the subscription itself likely has other properties
(expiration date, for example), you don’t want to model that as a
HABTM.
I think you probably want to do user has_many (or has_one)
subscriptions, and subscriptions has_many_and_belongs_to newsletters.
–
- Adam
** Expert Technical Project and Business Management
**** System Performance Analysis and Architecture
****** [ http://www.everylastounce.com ]
Just as an example in that case how would I select all users that had a
subscription to newsletter 2?
Jim
Adam F. wrote:
On Thu, Feb 09, 2006 at 10:39:36PM -0700, Jim J. wrote:
proper way to perform this type of relationship or is it something
where I would give the newsletter model a has_and_belongs_to_many
users relationship? I’m not quite sure how to go about it. Any advice?
Because the subscription itself likely has other properties
(expiration date, for example), you don’t want to model that as a
HABTM.
I think you probably want to do user has_many (or has_one)
subscriptions, and subscriptions has_many_and_belongs_to newsletters.
–
- Adam
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.