Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support case-sensitive uniqueness validation #221

Closed
wants to merge 2 commits into from

Conversation

shioyama
Copy link
Owner

@shioyama shioyama commented May 9, 2018

This is a first attempt to leverage the new query plugin added in #216. The PG nodes were missing support for LOWER so I've added it.

Related: #141

@shioyama shioyama mentioned this pull request May 9, 2018
@Gbeschbacher
Copy link

Hi @shioyama, is this PR also related to do a uniqueness validation of an attribute with json backend? As an example, i've got an attribute and 2 locales and i want that the attribute is unique based on the locale scope.

@shioyama
Copy link
Owner Author

shioyama commented May 22, 2018

@Gbeschbacher Yes, Mobility currently already supports uniqueness by locale for every backend, see here. However it is case-sensitive uniqueness only.

I'm planning to support case-insensitive uniqueness as well once some big changes are done. Currently if you try to use case insensitive uniqueness Mobility will issue a warning telling you it is not supported.

@Gbeschbacher
Copy link

Gbeschbacher commented May 22, 2018

Thanks for the very fast reploy @shioyama! I'm also already using MySQL in the same Setup as metioned here. Guess I'm having some problems with MySQL there not related to your gem.

Class Category
  extend Mobility
  translates :name
  validates :name, uniqueness: true, presence: true
end

Category.find(1).update!(name: "foobar") gives me an

ActiveRecord::StatementInvalid: Mysql2::Error: Invalid JSON path expression. The error is around character position 1.: SELECT  1 AS one FROM `categories` WHERE (`categories`.`name` ->> 'en') = 'foobar' AND `categories`.`id` != 1 LIMIT 1
from /usr/local/bundle/gems/mysql2-0.5.1/lib/mysql2/client.rb:131:in `_query'

EDIT: if this is any relevant for you, please tell me so and i'll post that wherever you want it to have it. If this is irrelevant, feel free to delete it.

@shioyama
Copy link
Owner Author

@Gbeschbacher I'm really not very familiar with JSON support by MySQL, but what I found indicates you need to be using at least version 5.7.13 for the ->> operator to be supported.

EDIT: if this is any relevant for you, please tell me so and i'll post that wherever you want it to have it. If this is irrelevant, feel free to delete it.

Yes I am actually very interested. I don't think it should be very hard to support MySQL JSON, just a matter of getting the right syntax. So any notes you have, please go ahead and post them here and I will use them in the future (although maybe not for a while...)

@shioyama
Copy link
Owner Author

Hmm, reading the MySQL docs now, looks like perhaps the syntax is actually a bit different: c->>'$.name', which is similar but different to PostgreSQL. That would explain the error you see.

@shioyama
Copy link
Owner Author

I'm closing this since before we can support case-insensitive uniqueness validation, we need to support lower on all backend nodes. Currently it is missing from json/jsonb/hstore/container backends.

@shioyama shioyama closed this May 27, 2018
@shioyama shioyama deleted the case_sensitive_uniqueness branch May 29, 2018 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants