On Feb 14, 2011, at 9:53 AM, Lille wrote:
Jim,
Thanks, but your proposed RecordOwner would have no behavior distinct
from User and would not describe the relationship from the Project
model's perspective. My User shouldn't care about the kind of relation
it has to Project, rather the reverse.
My pseudocode is about as specific as I know how to get.
To recap in its most distilled form, my problem is what relationships
to include in two models, User and Project, where a User may be
associated with Project in any of three ways -- User,
'primary_record_owner', or 'record_owner, such that the following
expressions are possible:
1) @user.projects # returns all projects associated with a User
instance
2) @project.primary_record_owner # returns a User instance
3) @project.record_owners # returns a collection of User instances
4) @project.users # returns a collection of User instances
I think I see how to accomplish 2-4, using HABTM, but I don't see how
to accomplish 1) at the same time.
Have you thought about a polymorphic join model between the two, like
maybe a Role? That's how I ended up structuring a recent project.
Walter
Thanks,
Lille
On Feb 13, 8:41 pm, Jim Ruther Nill <[email protected]> wrote:
I'm thinking about 4 models
- User
- Project
- RecordOwner
- UserProject -> this is the join table for user and project
You won't need RecordOwner if record_owners is a subset of the users
association.
Give us an example so we can help out with the options you want.
On Mon, Feb 14, 2011 at 8:17 AM, Lille <[email protected]>
wrote:
Hi,
I want to specify relationships between two classes like that
expressed in the following pseudocode:
class User < ActiveRecord::Base
has_many :projects
end
class Project < ActiveRecord::Base
has_one
:primary_record_owner, :<pseudo_option_for_referring_to>=>"User"
has_many :record_owners, :<pseudo_option_for_referring_to>=>"User"
has_many :users # this refers to User, too
end
From the above I seek the following kind of results:
@user.projects # returns all projects associated with the user from
any of the three User associations in Project
@project.primary_record_owner # returns the User instance
@project.record_owners # returns the collection of User instances
@project.users # returns User instances, not necessarily overlapping
with the other associations
The intent I mean to express is that a Project can have any of three
levels of relationship with a User, while a User has only one
level of
association with a Project.
I was thinking HABTM, but I don't see how to get my desired
'[email protected]' result from that.
Any helpful comment would be greatly appreciated.
Thanks,
Lille
--
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.
--
-------------------------------------------------------------
visit my blog athttp://jimlabs.heroku.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 rubyonrails-
[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
.
--
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.