jasonmk / datastax_rails

A Ruby-on-Rails interface to Datastax Enterprise. Replaces the majority of ActiveRecord functionality.
MIT License
23 stars 9 forks source link

Update with composite keys #24

Closed davidkelley closed 10 years ago

davidkelley commented 10 years ago

I seem to be having difficulties updating column families that have composite keys. I get the following error:

Missing mandatory PRIMARY KEY part pricing_date

Using CQL_DEBUG I can see that the query composed is:

UPDATE stock_data SET "price" = ? WHERE id IN (?)

Looking over the documentation for CQL, I believe that it should be something similar to:

UPDATE stock_data SET "price" = ? WHERE id = ? AND pricing_date = ?

The relevant parts from my model are:

class StockData < DatastaxRails::WideStorageModel
  self.column_family = 'stock_data'
  self.primary_key = :id
  self.cluster_by = :pricing_date
  self.create_options = 'CLUSTERING ORDER BY (pricing_date DESC)'
  uuid :id
  time :pricing_date
  float price
end

Is this a bug or am I doing something wrong? I am happy to send a PR for a fix if you are able to point me in the right direction.

jasonmk commented 10 years ago

You're right, that's definitely a bug, though I'm baffled why I haven't run across it before. It looks like the CQL update generator needs a little work. I'm currently looking at another bug in the persistence code, so I'll take a look at this too.

davidkelley commented 10 years ago

Brilliant. As I mentioned, let me know if you need any help completing the work . Happy to help out with this.

jasonmk commented 10 years ago

Version 2.0.8 should fix it. Thanks for the report!

jasonmk commented 10 years ago

Just bumped to 2.0.9. 2.0.8 broke migrations. I really need to come up with a way to spec those....

davidkelley commented 10 years ago

Ahh yes, was just debugging this myself

davidkelley commented 10 years ago

Thanks for fixing it. I'll take a look over the spec tests and see if I can figure something out, happy to contribute back.

jasonmk commented 10 years ago

That would be great. Thanks and good luck!