1

For example, I have table names: id integer primary key, name text unique and unique index for names(name).

I want to select records by index-style syntax: (n12, nBill) = (Name[12], Name['Bill']) or with Name.get['Smitt'].

As documentation says, it can be done with "natural keys", but how create them at SQLite?

update:
@Frost: As Spotlight on... Composite Keys says, records with composite keys must be called with both keys: Name.get(1, 'Smitt'), it is wrong for me. I need something to select record by any key:

Name[1] == Name['Smitt'].

emett
  • 128
  • 13

1 Answers1

0

As the property docs say, you can create natural keys by passing :key => true to your :name property, like so:

class Name
  property :name, :unique => true, :key => true
end

That should enable you to do Name["Bill"] or Name.get("Bill").

If you add :key to more than one property, you can have composite keys as well.

Frost
  • 11,121
  • 3
  • 37
  • 44
  • I confused: when I have `id, Serial` and `:name, :key=>true`, auto_migrade generate only single primary key for `id` and 2 unique indexes, for `name` and for `id`. When I change `Serial` to `Integer, :unique=>true, :key=>true`, auto_migrate will generate `PRIMARY KEY("id", "name")`. Why so? – emett Apr 12 '12 at 17:20