On 11 January 2016 at 04:30, Shabbir Ahmed <[email protected]> wrote: > 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.
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsYXWesLpuMH%3DeJX8c-7Az-Rr_XaKa0cvxzZiQU6%2BWT%2Bw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

