I don't think you could do all of this with the standard
nested_attributes on the book model, you'd need to write your own setter
method. Ultimately you're going to be creating an authoring_role
object, and either finding an existing author or creating a new author,
and the same for the role.
>
> Rails finds it easier to use foreign keys based on id. Are we talking
> about rails or about a person manually searching the database using
> their hands and eyes?
>
A person manually scanning the database (in a MySQL command prompt).
If this was actually a useful table (as opposed to just i
Andy Jeffries wrote:
>>
>> Also by using a string for the role_type you will have many Role
>> records with "MAIN_AUTHOR" for example. If you later decided that
>> "Primary Author" would be better you would have to change the string
>> in many records.
>
>
> I'm not saying MAIN_AUTHOR has to be
Also, your system doesn't easily let you attach properties or behaviour
to a given role. Presumably you would have a field 'name', or something
similar, in the roles table, and you could hang behaviour on the value
of the name but again it's clumsy and messy and fragile, and creates a
lot of r
Hi Andy - why not just post your code here? Saves clicking away, and
it's easier to discuss the code. Anyway, you posted
class Role < ActiveRecord::Base
belongs_to :author
belongs_to :book
end
class Book < ActiveRecord::Base
has_many :authors, :through => :roles
has_many :roles
end
cl
5 matches
Mail list logo