For suppose I have three database table eg:
users:
------------------------------------
user_id | name | email |
------------------------------------
1 | xyz | [email protected] |
------------------------------------
companies:
------------------------------------
company_id | user_id | c_name |
------------------------------------
1 | 1 | abc |
------------------------------------
posts:
------------------------------------
post_id | company_id | post_title |
------------------------------------
1 | 1 | etc |
------------------------------------
This is my database.
Now I need at first I signup then create 1 or 2 or 3 companies into one user_id then create post into company_id.
Now create company under user also create post but not update company_id in post table below my code:
user model:
has_many :companies
company model:
has_many :posts, :foreign_key => :company_id
belongs_to :user
post model:
belongs_to :user
belongs_to :company
How can I reach this solution?
Thanks