views:

17

answers:

1

I'm using rails3.rc and activerecord3 (with meta_where) and just started to switch to sequel, because it seems to be muuuuch faster and offers some really great features :-)

I'm already using the active_model plugin (and some others). But here are some questions I found and which I didn't find any documentation for:

  1. As far as I know, I should use User[params[:id]] instead of User.find(params[:id]). But his doesn't raise if no record exists and doesn't convert the value to an integer (type of PK), so it's as a string in the where clause. I'm not sure if this is causing any performance issues (do all db servers still use keys properly?). Does this harm identity_map? What's the best way to solve these both issues?

  2. Is there an easy way to flip the usage of associations like User.messages_dataset and User.messages? So that User.messages behaves like in AR (=User.messages_data_set). I guess I'd use the #..._dataset a lot but never need the array method, because I could just add .all?

  3. I noticed some same (complex) queries are executed several times within one action sometimes. Is there something like the AR query cache? (identity_map doesn't seem to work for these cases).

  4. Is there a #to_sql I can call to get the raw SQL a dataset would produce?

Thanks for any hints :-)

+1  A: 
  1. You can either use:

    User[params[:id].to_i] || raise Sequel::Error

    Or write your own method that does something like that. Sequel supports non-integer primary keys, so it wouldn't do the conversion automatically. It shouldn't have any affect on an identity map. Note that Sequel doesn't use an identity map unless you are using the identity_map plugin. I guess the best way is to write your own helper method.

  2. Not really. You can use the association_proxies plugin so that non-array methods are sent to the dataset instead of the array of objects. In general, you shouldn't be using the association dataset method much. If you are using it a lot, it's a sign that you should have an association for that specific usage.

  3. There is and will never be a query cache. You should write your actions so that the results of the first query are cached and reused.

  4. Dataset#sql gives you the SELECT SQL for the dataset.

Jeremy Evans