Tuesday 9 April 2013

No identification of primary key on legacy database table

When using Rails against existing databases, it is unlikely that the Rails naming conventions for tables has been used. This means that models are likely to require the table name to be specified.

The old directive set_table_name has been removed from Rails. You now need to use:
self.table_name= :theTableName
However, this appears to have introduced a break, at least in Rails 4. Specifying the table name on a table that has id as the key column doesn't result in Rails identifying the key column, you still need to specify it:
self.primary_key= :id
 This means that whenever you set the table_name, you have to also set the primary key column name.

1 comment:

  1. Most boardrooms are by now well aware of the benefits of cloud computing and its important role in any company's formal IT portfolio. Yet many businesses remain sceptical about data security, with 87 per cent of financial services organisations admitting they do not plan to migrate their most important applications to the best data rooms due to security concerns.

    ReplyDelete