On Nov 16, 7:51 pm, mlb5000 [email protected] wrote:
I have a database table, users, which has a referrer_id column. This
column maps back to the users table to denote the user who referred
this record. How can I accomplish this type of reference with the
t.references call in my create_table without needing to create some
sort of crazy (and unnecessary) intermediate table? I’d like the
column name to remain referrer_id so the intention of the column is
I’m not sure I understand - you’ve already got the column so why are
you worrying about the migration ?
t.references doesn’t do any magic - it just adds _id to the end and
creates a column of the right type (IIRC in recent versions of rails
if it’s also generating the model class it will insert the belongs_to
into the model too)
Anyway the point is that the migration is dumb, it just adds a column.
In terms of making that association work your association will need to
specify the :class_name option and so on.