Thursday, August 9, 2012

[Rails] Re: Re: Re: Rails Nested Form

Colin Law wrote in post #1071831:
> On 9 August 2012 16:14, Jean-Sbastien D. <lists@ruby-forum.com> wrote:
>>> it a one to one relationship?
>>>
>>> Colin
>>
>> A customer has many BookManager
>> A bookManager has one book
>
> That is only half of the associations. How many customers are
> associated with each manager and how many book managers are associated
> with each book?
>
> Show us the model relationships that the above implies for each model.
>
> Colin

Here what I build up with has many

class Book < ActiveRecord::Base
# RELATIONSHIP
belongs_to :book_manager
def customer
book_manager.customer
end
attr_accessible :book_manager_id, :description
class BookManager < ActiveRecord::Base
# RELATIONSHIP
belongs_to :customer
has_one: :book
accepts_nested_attributes_for :books, allow_destroy: :true
attr_accessible :customer_id, :visible, :books_attributes
class Customer < ActiveRecord::Base
# RELATIONSHIP
has_many :book_managers
has_many :books, :through => :book_managers
accepts_nested_attributes_for :book_managers, allow_destroy: :true
attr_accessible :admin, :first_name, :last_name, :middle_name, :email,
:email_confirmation, :password, :password_confirmation, :image,
:book_managers_attributes, :locale

I think his a correct relationship model.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate