multiple context problem #268

Open
nunziofiore opened this Issue Jul 14, 2012 · 3 comments

Projects

None yet

2 participants

@nunziofiore

have two context:

:tags :systemtags

I have somthing like

 @digitalassets1 = Digitalasset.order(:updated_at)
 @digitalassets1 = @digitalassets1.where(:name => ?, name) if (name)
 @digitalassets1 = @digitalassets1.tagged_with(params[:tg], :on => :tags) 
 @digitalassets1 = @digitalassets1.tagged_with(params[:tg], :on => :systemtags)
 @digitalassets = @digitalassets1.page(params[:page])

the query on the tags doesn't run if the tag is in system tags because it search in tags and systemtags, how can I compose in OR the two tagged_with query?

I try to explain better with console:

1.9.2-p290 :032 > def test_tag
1.9.2-p290 :033?>   d = Digitalasset.order(:updated_at)
1.9.2-p290 :034?>   d = d.tagged_with(['Hygiene'],:on=>:tags)
1.9.2-p290 :035?>   d = d.tagged_with(['Hygiene'],:on=>:tags)
1.9.2-p290 :036?>   end
 => nil 
1.9.2-p290 :037 > test_tag
  ActsAsTaggableOn::Tag Load (3.7ms)  SELECT `tags`.* FROM `tags` WHERE (lower(name) = 'hygiene')
  ActsAsTaggableOn::Tag Load (2.5ms)  SELECT `tags`.* FROM `tags` WHERE (lower(name) = 'hygiene')
  Digitalasset Load (3.6ms)  SELECT `digitalassets`.* FROM `digitalassets` JOIN taggings     digitalasset_taggings_31c69d2 ON digitalasset_taggings_31c69d2.taggable_id = digitalassets.id AND digitalasset_taggings_31c69d2.taggable_type = 'Digitalasset' AND digitalasset_taggings_31c69d2.tag_id = 3498 AND digitalasset_taggings_31c69d2.context = 'tags' JOIN taggings digitalasset_taggings_9748c92 ON digitalasset_taggings_9748c92.taggable_id = digitalassets.id AND digitalasset_taggings_9748c92.taggable_type = 'Digitalasset' AND digitalasset_taggings_9748c92.tag_id = 3498 AND digitalasset_taggings_9748c92.context = 'tags' ORDER BY updated_at
 => [#<Digitalasset id: 341468, BLABLABLA A LOT OF RESULTS from_docs: "N", docs_id: "">] 

but if I want to search Digitalasset tagged both on tags either on systags like that

1.9.2-p290 :038 > def test_tag
1.9.2-p290 :039?>   d = Digitalasset.order(:updated_at)
1.9.2-p290 :040?>   d = d.tagged_with(['Hygiene'],:on=>:tags)
1.9.2-p290 :041?>   d = d.tagged_with(['Hygiene'],:on=> :systags)
1.9.2-p290 :042?>   end
 => nil 
1.9.2-p290 :043 > test_tag
  ActsAsTaggableOn::Tag Load (4.2ms)  SELECT `tags`.* FROM `tags` WHERE (lower(name) = 'hygiene')
  ActsAsTaggableOn::Tag Load (3.6ms)  SELECT `tags`.* FROM `tags` WHERE (lower(name) = 'hygiene')
  Digitalasset Load (1.4ms)  SELECT `digitalassets`.* FROM `digitalassets` JOIN taggings digitalasset_taggings_09749ee ON digitalasset_taggings_09749ee.taggable_id = digitalassets.id AND digitalasset_taggings_09749ee.taggable_type = 'Digitalasset' AND digitalasset_taggings_09749ee.tag_id = 3498 AND digitalasset_taggings_09749ee.context = 'tags' JOIN taggings digitalasset_taggings_dc1d5ba ON digitalasset_taggings_dc1d5ba.taggable_id = digitalassets.id AND digitalasset_taggings_dc1d5ba.taggable_type = 'Digitalasset' AND digitalasset_taggings_dc1d5ba.tag_id = 3498 AND digitalasset_taggings_dc1d5ba.context = 'systags' ORDER BY updated_at
 => [] 
@nunziofiore

I FOUND IT:

1.9.2-p290 :006 > d = Digitalasset.tagged_with(["mytagvalue"], :on => :tags || :systags)

@nunziofiore nunziofiore reopened this Jul 15, 2012
@nunziofiore

no I was wrong :( it's not fixed in that way

@manuelmeurer

Workaround:

Digitalasset
  .tagged_with(['Hygiene'], :on => :tags)
  .where(:id => Digitalasset.tagged_with(['Hygiene'], :on=> :systags).pluck(:id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment