The has_many side you'll always need to do by editing the model file, but
the belongs_to side you can do with either of these:

rails g model User name:string group:belongs_to

# or

rails g model User name:string group:references


Both will create the appropriate group_id field in your migration and add a
belongs_to line to your model class.

On Sat, Aug 13, 2011 at 2:47 PM, jvictor <[email protected]> wrote:

> When we generate the model, is there a way we can specify the
> relationships between entities or should we create the model without
> the relations, edit the model and generate a migration specifically
> for it ?
>
> I was expecting that we can get it working by typing in these..
>
> rails generate model Group name:string has_many:users
>
> rails generate model User name:string passcode:string
> belongs_to:groups
>
> But when I try to run the db migrate it says undefined method users or
> so..
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
>

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to