I am not sure how to create an event at all time but still keeping data integrite correct.
Here are my models
Customer
id
first
last
email
Book
id
description
Book_Manager
customer_id
book_id
visible
In order to do this I have to use a has_many relationship and his describe has below
Book
has_many :book_managers
has_many :customers, :through => :book_managers
Book_Manager
belongs_to :customer
belongs_to :book
Customer
has_many :book_managers
has_many :books, :through => :book_managers
The idea is to see the data already created from previous time, which mean I would have to create a query where Book = Book_Manager Table where customer_id = current_customer and created_last. I am not to sure how would i create a query like this in the book controllers. I believe it may look like has follow for the query. I am correct? Current customer is the current customer in sessionHelper method
@report = BookManager where customer.id == current_customer.id AND created_last.last
Last but not least, everytime the customer modify the text by pressing save, The action create would be executed, and create a new book_manager with the correct 3th model books associated with and customer also associated with the book manager.
I have the following code but i am not sure if its correct
class BooksController < ApplicationController
def edit
@book = Book.find(params[:id])
end
def create
@customer = Customer.first
@book = @customer.BookManager.build(params[:book])
end
end
As you have the
have_many throughyou don’t need to refer the join table (Book_Manager). You can access it directly: