mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.96k stars 1.19k forks source link

issue with untagged (or not tagged) #1033

Open francescor opened 3 years ago

francescor commented 3 years ago

I've defined this to get untagged entries

class TimeEntry < ApplicationRecord
...
  def self.untagged
    tagged_with(self.all_tag_names, exclude: true)
  end

which works fine if I want all untagged items: TimeEntry.untagged

It does not work (always return []) if I call it on a TimeEntry::ActiveRecord_Relation

TimeEntry.where(....).untagged

while it works if I get untagged items with

class TimeEntry < ApplicationRecord
...
  def self.untagged
    self.select { |time_entry| time_entry if time_entry.tag_list.empty? }
  end

Is it me, doing something I should not?

c2ofh commented 3 years ago

Hi @francescor

I helped me out to find untagged entries by this statement (with your class-name):

scope :untagged, -> { left_outer_joins(:tags).where(tags: { id: nil }) }