I wrote a proper one last night.  I'll share the code, but it's under my own 
namepsace at the moment and needs a little configuration and some specs writing 
;)  It just provides a property type of Sequence as opposed to Serial, which 
optionally takes a :sequence_name if it doesn't follow convention.

class User
        include DataMapper::Resource
        
        storage_names[:default] = :user
        
        property :id,              Sequence,   :field => 'userid' # , 
:sequence_name => 'user_userid_seq'

end


El 06/05/2011, a las 08:08, Xavier (DBIYF) escribió:

> 
> 
> On 5/05/11 9:06 PM, Chris Corbyn wrote:
>> I've already solved this in my app.  We are using DM with a legacy
>> schema (still in use by another app, so cannot be modified too much)
>> and all of the PK's are generated from a sequences table (it's just
>> `name` and `id` columns).
>> 
>> I've just done this with a "before :create" hook in my models, and the
>> logic is just:
>> 
>> SELECT id FROM sequences WHERE name = sequence_name FOR UPDATE
>> UPDATE sequences SET id = id + 1 WHERE name = sequence_name
>> 
>> I can't help but feel I've reinvented the wheel given that this is
>> such a common design pattern, so does anyone know of a plugin that
>> handles Serial fields via a sequences table?
> I haven't heard of one
> 
>> 
>> Cheers,
>> 
>> Chris
>> 
> 
> -- 
> 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.
> 

-- 
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