Naming assumptions, and how to override them

Lafcadio assumes that each table has a single primary key named pk_id. This can be overridden by using DomainObject.sql_primary_key_name.

class User < Lafcadio::DomainObject
  strings 'fname', 'lname'
  sql_primary_key_name 'user_id'

No matter what the primary key is named in the database, in your Ruby code you'll always call DomainObject#pk_id.

Similarly, Lafcadio assumes that the database name of the table is the same as the class name, only lower-case, pluralized, and with underscores instead of camel case.

class User < Lafcadio::DomainObject; end
puts User.table_name          # "users"
class BlogEntry < Lafcadio::DomainObject; end
puts BlogEntry.table_name     # "blog_entries"

You can override this behavior by calling DomainObject.table_name and passing it an argument.

class BlogEntry < Lafcadio::DomainObject
  table_name 'some_other_table'
puts BlogEntry.table_name     # "some_other_table"