relationing has_many, belongs_to

userid cannot be both the primary key and a foreign key.

Rein

@member.matrix.new returns a new matrix object. you have to assign it
to a variable:

def create
    @member = Member.new(params[:member])
    @new_matrix = @member.matrix.new
    @new_matrix.userid = @member.userid
    @new_matrix.parent = params[:parent]
....
end

about foreign keys: in the has_many, you define parent as the foreign
key, in the belongs_to, you define userid as foreign key. but it has
to be the same on both sides, otherwise it's no proper relation,
legacy Database or not.
You tell the Member model that is has many Matrix' associated through
the parent column in the matrix table, but you tell the Matric Model
that it belongs to a Member associated by the userid column in the
matrix table ... it should say "parent" here to, because the table on
the has_many side doesn't have a foreign key, only the belongs_ to
side

You've defined userid as the primary key, which makes it accessable as
id (ie @matrix.id) rather than userid. The problem here, though, is
manifold:

Rails expects your database to be sane, which includes an id column
that is a unique auto-incrementing integer.

Using it as a foreign key means that you'll have to *set* the primary
key of the record, which is a huge no-no in both rails and database
design and violates the auto-incrementing requirement.

Using is as a foreign key also implies that two records could share
the same foreign key, and therefore the same primary key, which
violates the unique requirement.

Rails can work with most legacy databases provided that they're
relatively sane. Using a primary key as a foreign key is most
definitely insane and I doubt you'd make that table work properly with
or without rails.

Rein