Ruby on Rails DB Relation

For suppose I have three database table eg:
recruiters

recruiter_id | name | email |

1 | xyz | [email protected] |

companies

company_id | recruiter_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
recruiter_id then create post into company_id.

Database already created but How can I relation this model.

Thanks

On 11 January 2016 at 04:30, Shabbir A. [email protected] wrote:

company_id | recruiter_id | c_name |

This is my database.

Now I need at first I signup then create 1 or 2 or 3 companies into one
recruiter_id then create post into company_id.

Database already created but How can I relation this model.

I assume that you are a newcomer to rails. You have not used the
rails convention for naming the primary id field in each table, which
is a bad idea, it is better to stick to the conventions unless there
is very good reason. I suggest before going further that you work
right through a good tutorial such as railstutorial.org (which is free
to use online). That will show you the basics of rails. You will
recover the time spent on this very quickly.

However, back on the specific problem, you are looking at the problem
from the wrong end. You should not say “this are my tables, what
should the associations be”, but rather “this is my problem, what are
the associations” from which you can design the tables. It looks from
your description of the problem that you want

Recruiter has_many companies

Company belongs_to recruiter
Company has_many posts

Post belongs_to company

But as I said, please work through the tutorial before going further.
Also look at the Rails Guides.

Colin