From 0a6ed3ce328febea1f6122b04c0acda561a535fe Mon Sep 17 00:00:00 2001 From: Robin B Date: Thu, 20 Oct 2016 10:40:03 +0200 Subject: [PATCH] Add chapter about limitations #4 --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 41c4195..993af4d 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,21 @@ Page.create!(:title_en => 'Another English title', :title_de => 'Noch ein Deutsc Page.where(title: 'Another English title') # => Page ``` +### Limitations +`awesome_hstore_translate` patches ActiveRecord, which create the limitation, that a with `where` chained `first_or_create` and `first_or_create!` **doesn't work** as expected. +Here is an example, which **won't** work: + +``` ruby +Page.where(title: 'Titre français').first_or_create! +``` + +A workaround is: + +``` ruby +Page.where(title: 'Titre français').first_or_create!(title: 'Titre français') +``` + +The where clause is internally rewritten to `WHERE 'Titre français' = any(avals(title))`, so the `title: 'Titre français'` is not bound to the scope. ### Upgrade from [`hstore_translate`](https://github.com/Leadformance/hstore_translate) 1. Replace the [`hstore_translate`](https://github.com/Leadformance/hstore_translate) with `awesome_hstore_translate` in your Gemfile