Hi Earle, > I'm using DM on a legacy sqlite3 database where the primary keys are > defined as: "id INTEGER PRIMARY KEY" > > I'm trying to match this in the property definition for id, but I can't > get it quite right. Below are the property definitions I've tried, the > generated SQL, and why they don't work the way I need. > > 1) property :id, Serial # id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT > 2) property :id, Integer, :key => true # id INTEGER NOT NULL, PRIMARY > KEY(id) > > Method 1 would be great if there was a way to turn off AUTOINCREMENT. > That keyword causes a slightly different and less efficient to be used > than the default key selection algorithm.
The "Serial" type is for auto-increment primary keys. More loosely it can be thought of as "this field value is generated by the system during record creation". > Method 2 causes :id to be nil unless I specify it, which is not > acceptable for a number of reasons. Really? Shouldn't the NOT NULL prevent nil values from being inserted? If you're using dm-validations it should not allow you to create a record where a key is nil either. > Is there a way (apart from hacking DM) to generate either of the > following SQL with a property definition? > > id INTEGER PRIMARY KEY > - or - > id INTEGER NOT NULL PRIMARY KEY The second statement above appears to be the same as what's generated for: property :id, Integer, :key => true Also, if this is a legacy database, does it matter what properties it uses when doing auto-migrate, provided you have something equivalent? Thanks, Dan (dkubb) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
