While I agree with Jason, using belongs_to in your migration has one major benefit: it automatically adds an index on the foreign key, and that's something most people forget ;)
- Matt On Tue, Aug 23, 2011 at 3:03 PM, Jason King <[email protected]> wrote: > There are many points where the law of diminishing returns means that Rails > stops and just leaves the rest up to the developer. There's enough room for > error with has_many associations that this is one of those points. Even the > above code that creates the belongs_to side of the association is not > something that I ever actually remember to use. Opening the model file, and > adding the line manually is just so easy to do that it's not worth it for my > brain to think about this at the time I'm generating the migration. > > On Tue, Aug 23, 2011 at 2:03 PM, jvictor <[email protected]> wrote: > >> Thanks guys that worked. Any reason why rails does not "do the right >> thing" to setup a model with has_many ? >> >> On Aug 15, 5:21 pm, Jarin Udom <[email protected]> wrote: >> > Just for clarity, you don't need to make any database table changes to >> the >> > has_many model, unless you want a counter cache (in which case you would >> add >> > a users_count integer field to the groups table with a default value of >> 0, >> > and set :counter_cache => true on the belongs_to model). >> > >> > Jarin >> >> -- >> SD Ruby mailing list >> [email protected] >> http://groups.google.com/group/sdruby >> > > -- > SD Ruby mailing list > [email protected] > http://groups.google.com/group/sdruby > -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
