Hi,

The :key clause occurs in the class definition for the table. The docs
are kind of disjointed, but you can find out more by checking these...

http://datamapper.org/doku.php?id=docs:properties#natural_keys

Notice that you can define composite keys by using a common symbol.
That's one thing that drew me to DM over ActiveRecord.

http://jlaine.net/2008/6/2/specifying-indeces-in-datamapper

Note that there's ":key" and there's ":index". The difference? Here's
some sample output and dumps from the database:

<pre>
class NewReminder
        include DataMapper::Resource

        property        :id,                            Serial
        property        :is_active,                     Boolean
        property        :owner,                         Integer
        property        :description,           Text,   :key => true
        property        :reminder_time,         DateTime
end

                                       Table "public.new_reminders"
    Column     |            Type             |
Modifiers
---------------+-----------------------------
+------------------------------------------------------------
 id            | integer                     | not null default nextval
('new_reminders_id_seq'::regclass)
 is_active     | boolean                     |
 owner         | integer                     |
 description   | text                        | not null
 reminder_time | timestamp without time zone |
Indexes:
    "new_reminders_pkey" PRIMARY KEY, btree (id, description)

class NewReminder
        include DataMapper::Resource

        property        :id,                            Serial
        property        :is_active,                     Boolean
        property        :owner,                         Integer
        property        :description,           Text,   :index => true
        property        :reminder_time,         DateTime
end

                                       Table "public.new_reminders"
    Column     |            Type             |
Modifiers
---------------+-----------------------------
+------------------------------------------------------------
 id            | integer                     | not null default nextval
('new_reminders_id_seq'::regclass)
 is_active     | boolean                     |
 owner         | integer                     |
 description   | text                        |
 reminder_time | timestamp without time zone |
Indexes:
    "new_reminders_pkey" PRIMARY KEY, btree (id)
    "index_new_reminders_description" btree (description)

class NewReminder
        include DataMapper::Resource

        property        :id,                            Serial
        property        :is_active,                     Boolean
        property        :owner,                         Integer,        :index 
=> [:owner_desc]
        property        :description,           Text,           :index => 
[:owner_desc]
        property        :reminder_time,         DateTime
end

                                       Table "public.new_reminders"
    Column     |            Type             |
Modifiers
---------------+-----------------------------
+------------------------------------------------------------
 id            | integer                     | not null default nextval
('new_reminders_id_seq'::regclass)
 is_active     | boolean                     |
 owner         | integer                     |
 description   | text                        |
 reminder_time | timestamp without time zone |
Indexes:
    "new_reminders_pkey" PRIMARY KEY, btree (id)
    "index_new_reminders_owner_desc" btree (owner, description)

class NewReminder
        include DataMapper::Resource

        property        :id,                            Serial
        property        :is_active,                     Boolean
        property        :owner,                         Integer,        
:unique_index => true
        property        :description,           Text
        property        :reminder_time,         DateTime
end

                                       Table "public.new_reminders"
    Column     |            Type             |
Modifiers
---------------+-----------------------------
+------------------------------------------------------------
 id            | integer                     | not null default nextval
('new_reminders_id_seq'::regclass)
 is_active     | boolean                     |
 owner         | integer                     |
 description   | text                        |
 reminder_time | timestamp without time zone |
Indexes:
    "new_reminders_pkey" PRIMARY KEY, btree (id)
    "unique_index_new_reminders_owner" UNIQUE, btree (owner)

class NewReminder
        include DataMapper::Resource

        property        :id,                            Serial
        property        :is_active,                     Boolean
        property        :owner,                         Integer,        
:unique_index => [:owner_desc]
        property        :description,           Text,           :unique_index 
=> [:owner_desc]
        property        :reminder_time,         DateTime
end

                                       Table "public.new_reminders"
    Column     |            Type             |
Modifiers
---------------+-----------------------------
+------------------------------------------------------------
 id            | integer                     | not null default nextval
('new_reminders_id_seq'::regclass)
 is_active     | boolean                     |
 owner         | integer                     |
 description   | text                        |
 reminder_time | timestamp without time zone |
Indexes:
    "new_reminders_pkey" PRIMARY KEY, btree (id)
    "unique_index_new_reminders_owner_desc" UNIQUE, btree (owner,
description)

</pre>

So, there's some nice control over what we can do!

GF

On Jul 14, 1:38 pm, Ashley Moran <[email protected]>
wrote:
> Hi
>
> Is there a way to mark a non-serial column (or set of columns) as a  
> key in a migration file?  After looking through the code, I am under  
> the impression the only columns that can be defined as keys are  
> Serials.  (And then, it's implicit.)
>
> Thanks
> Ashley
>
> --http://www.patchspace.co.uk/http://www.linkedin.com/in/ashleymoranhttp://aviewfromafar.net/http://twitter.com/ashleymoran
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to