Sorry for the delay in getting back on this but I've just got back from a
weekend away.

Okay, so Max, you and I agree on the modelling for this concept so that
starts to narrow down where my problem is.

To begin with, I thought my problem was because I had a join model acting as
the parent to another join model and maybe the primary key of Authorings
wasn't being created before the join to AuthoringRole was being made.

Where we disagree is in the relationships and so this is obviously where my
problem lies.

I agree with all your relationships but I've added a bit extra ...... In my
book.rb, I have included accepts_nested_attributes_for :authors,
:authoring_roles
and also have a has_many :authoring_roles, :through => :authorings

I've done this because I want to accept all that information when creating a
book. when I say @book.save, I want it to include the roles as well as the
authors.

So how should I set that up? In my real world example Book == Account,
Author == Member and Role is one or many of Account Contact/Swimmer/etc.

When creating a new Book (Account), I am creating a new Author (Member) and
so the form accepts_nested_attributes_for :authors, :authoring_roles (in my
obviously mixed up logic)

If  I have a form where I accept Book, Author and Role information and then
want to create/update the Book, Author, Authorings and AuthoringRoles
through @book,save, how to go about it?

I'll have a play with this now and if I can break myself out of my cycle and
crack it, I'll get in touch. If you/someone provides me the solution before
that, I'd be grateful as this has been sending me mad.

Merci

-Ants



On 5 March 2010 14:10, Max Williams <[email protected]> wrote:

> I would do:
>
> Book
>  has_many :authorings
>  has_many :authors, :through => :authorings
>
> Authoring
>  belongs_to :book
>  belongs_to :author
>  has_many :authoring_roles
>  has_many :roles, :through => :authoring_roles
>
> AuthoringRole
>  belongs_to :authoring
>  belongs_to :role
>
> Role
>  has_many :authoring_roles
>  has_many :authorings, :through => :authoring_roles
>
> Author
>  has_many :authorings
>  has_many :books, :through => :authorings
>
> So, an 'authoring' encapsulates the concept of an author working on a
> book, and during that authoring process the roles they fulfilled are
> encapsulated in authoring_roles.
>
> Generally, it's good to approach this not from a data point of view, but
> from a real world concepts point of view.  The models should always try
> to encapsulate a real world concept, and have a name which describes
> that concept as simply as possible.
> --
> 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]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
100% naturally selected. 0% designed.

-- 
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