On May 20, 2:02 am, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
> I don't know if this is the problem, but I think you forgot Role
> has_many :memberships.
>

I don't think methods on the Role class should affect this in anyway.
I should only define the association if I benefit from the methods it
provides, right?  Or are there other effects I should be aware of?

Anyways, I gave this a try and the results are the same.

> I'll admit, though, that in this case I don't really see that the
> Membership model is any use.  Why aren't you just connecting User and
> Role directly?

Fair question.

You're probably right that this should be redesigned.  The reasons I
ended up with this are:
 1) Originally I had planned to have a has_many relationship between
user and role. When my plan changed I was lazy and didn't change
models/schema.
 2) Personal taste. I don't like to have empty fields in my database
by design.  If a record exists, all of the fields should have a
value.  This design lets a user have 0 or 1 roles and I test for this
by looking for the existance of a record in the join table.  I don't
know why this bothers me and it's probably irrational.  :)
 3) The example is somewhat contrived, though it does mimic an
application I'm writing.  I left out all of the fields for these
tables except the IDs so that I could demostrate the problem here.
--~--~---------~--~----~------------~-------~--~----~
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