Am I right in thinking that the member/group combination for a message is
always the same member/group that appears in a membership record?  If so
then would it be better to have

Membership:
has_many :messages
belongs_to :member
belongs_to :group
belongs_to :role

and

Message:
belongs_to :membership

Then you don't need the has_many :messages for Member or Group and I think
the whole thing is simpler.

2009/3/5 Pesho Petrov <[email protected]>

>
> Colin Law wrote:
>
> > Are you sure?  That seems incredibly complex.  For example a member has
> > many
> > roles, but it also has many memberships, each one of which belongs to a
> > role, so that is another set of roles a member may have.
> >
> > Does a message belong to a member, a group and a role or just one of
> > them at
> > a time?
>
> ok Colin, you're absolutely right! I'm afraid I've totally messed up my
> dependencies. This is my first time to handle database relationships
> through Rails models.
>
> So, I believe this is what I want to have:
>
> Member:
>  has_many :memberships, :dependent => :destroy
>   has_many :messages, :dependent => :destroy
>
> Group:
>   has_many :memberships, :dependent => :destroy
>  has_many :messages, :dependent => :destroy
>
> Role:
>  has_many :memberships, :dependent => :destroy
>
> Membership:
>  belongs_to :member
>  belongs_to :group
>  belongs_to :role
>
> Message:
>  belongs_to :member
>   belongs_to :group
>
> A message is supposed to be written by a member, who is a part of group.
> So I believe a message should belong to a member and a group.
> But different members from the same group can write different messages.
> And also, the same member, who is a part of different groups can write
> different messages on behalf of the different groups he/she is a part
> of.
>
> I hope the relationships above reflect well my expectations that I just
> described.
>
> Thanks in advance!
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to