I have three models in a Ruby on Rails application:
- Magazine
- Product
- Page
I want to use this query:
Magazine.find(1).products.first.pages
and get a page associated with appropriate product
but in page model I don’t want product_id be my foreign key I want number_id be my foreign key.
number is a field in product table.
how can change foreign key? because rails work with product_id as foreign key for page table.
tnx for your help.
I will write the appropriate codes for your models.
You can call Magazine.first.products.first.my_pages
and it will return correct results.