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

Tagged with, wildcard #587

Closed
CucumisSativus opened this issue Sep 11, 2014 · 7 comments
Closed

Tagged with, wildcard #587

CucumisSativus opened this issue Sep 11, 2014 · 7 comments

Comments

@CucumisSativus
Copy link

I have an issue with using tagged_with with wildcard. Calling it with a full name of a tag works great, but with only a part it does not. I decided to inspect it.

Company.tagged_with('zdrowa żywność', wild: true)
  ActsAsTaggableOn::Tag Load (0.5ms)  SELECT "tags".* FROM "tags"  WHERE (LOWER(name) = LOWER('zdrowa żywność'))
  Company Load (0.8ms)  SELECT "companies".* FROM "companies" JOIN taggings companies_taggings_caa133f  ON companies_taggings_caa133f.taggable_id = "companies".id AND companies_taggings_caa133f.taggable_type = 'Company' AND companies_taggings_caa133f.tag_id = 128 WHERE "companies"."removed" = 'f'
 => #<ActiveRecord::Relation [#<Company id: 14, (...)]>]>

As I mentioned this one is ok, but calling it with only a part of a name should return at least one record but it does not.

Company.tagged_with('zdrowa', wild: true)
  ActsAsTaggableOn::Tag Load (0.5ms)  SELECT "tags".* FROM "tags"  WHERE (LOWER(name) = LOWER('zdrowa'))
  Company Load (0.4ms)  SELECT "companies".* FROM "companies"  WHERE "companies"."removed" = 'f' AND (1 = 0)
 => #<ActiveRecord::Relation []>

Inspecting it deeper

Company.tagged_with('zdrowa', wild: true).to_sql
  ActsAsTaggableOn::Tag Load (0.6ms)  SELECT "tags".* FROM "tags"  WHERE (LOWER(name) = LOWER('zdrowa'))
 => "SELECT \"companies\".* FROM \"companies\"  WHERE \"companies\".\"removed\" = 'f' AND (1 = 0)"

Is there any logical explanation for AND (1 = 0) at the end of query?

My environment:
rails (4.1.4)
acts-as-taggable-on (3.3.0), from ruby-gems
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]

@seuros seuros added the bug!! label Sep 11, 2014
@seuros
Copy link
Collaborator

seuros commented Sep 11, 2014

Congratulations, you found an Easter egg in the gem. :trollface:

It's a bug, i will fix it.
As workaround put the tags into a array Company.tagged_with(['zdrowa'], wild: true).to_sql

@CucumisSativus
Copy link
Author

Unfortunately, not this time

Company.tagged_with(['zdrowa'], wild: true).to_sql
  ActsAsTaggableOn::Tag Load (0.7ms)  SELECT "tags".* FROM "tags"  WHERE (LOWER(name) = LOWER('zdrowa'))
 => "SELECT \"companies\".* FROM \"companies\"  WHERE \"companies\".\"removed\" = 'f' AND (1 = 0)"

@seuros
Copy link
Collaborator

seuros commented Sep 11, 2014

hmm

TaggableModel.tagged_with(['bob'], wild: true).to_sql
"SELECT \"taggable_models\".* FROM \"taggable_models\" JOIN taggings taggable_mod_taggings_5ce8fb5  ON taggable_mod_taggings_5ce8fb5.taggable_id = taggable_models.id AND taggable_mod_taggings_5ce8fb5.taggable_type = 'TaggableModel' AND taggable_mod_taggings_5ce8fb5.tag_id = 1"

Do you have a default scope ?

@CucumisSativus
Copy link
Author

Only on Company model

default_scope { where(removed: false) }

@seuros seuros added sql bug!! and removed bug!! labels Sep 11, 2014
@seuros
Copy link
Collaborator

seuros commented Sep 11, 2014

add 'any: true'

@CucumisSativus
Copy link
Author

Thanks, that workaround works

@SunnyTam
Copy link

better to state this on the readme. Thanks.

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

No branches or pull requests

3 participants