On Jan 19, 11:15 am, John Firebaugh <[email protected]> wrote: > IMO, unless overriden by set_primary_key, the order of symbols in the array > returned by Sequel::Model.primary_key should match the actual order of the > primary key:
I agree in theory, but to do so would require completely changing how the primary key is automatically set for a model. Currently, it loops over the table schema looking for ones that are primary keys, which is why the primary key is always going to be the same order the columns are in the table schema. Changing it to be the actual order of the primary key index is not be possible with Sequel's current database support. In most cases, it would have to parse the primary key indexes, and there isn't currently any support for that (DB#indexes leaves out primary key indexes). I would assume that having a composite primary key where the order of the primary key columns in the index differs from the order of the columns within the table schema would be an unlikely event, rare enough that using set_primary_key manually would be an appropriate solution. However, if you find this occurs often enough to be bothersome, I'll certainly consider changes to support it. The API I envision to support it would be a Database method (primary_keys_for_table?), which would take a table symbol/identifier and return an array of symbols for the order of the primary key columns in the primary key index (or raise an Error if not supported or the table doesn't exist). Then, Model subclasses could call that Database method first, using its results if it returns sucessfully, or falling back to the current code if not. If that sounds like something you want to implement, please send a pull request. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" 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/sequel-talk?hl=en.
