NoMethodError (undefined method `undiscarded?' ...
porterbayne opened this issue · comments
Describe the bug
When using the readme's proposed code for handling associations, I get this error when calling .kept
on a record:
undefined method `undiscarded?'`
Happens on both Discard 1.0 or 1.1.
(I am 99% sure this is some oversight on my part, but can't find it.)
To Reproduce
- I have an Encounter model and an Appointment model.
- Both have
include Discard::Model
as the first line in the model class code - Encounter
belongs_to
Appointment
class Encounter < ApplicationRecord
include Discard::Model
scope :kept, -> { undiscarded.joins(:appointment).merge(Appointment.kept) }
def kept?
undiscarded? && appointment.kept?
end
belongs_to :appointment, optional: true
...
end
Then in the Rails (5.2.3) console:
Encounter.first.kept?
Produces
NoMethodError (undefined method `undiscarded?' for #<Encounter:0x00007fc44fa9cb88>)
Did you mean? undiscard
discarded?
undiscard!
Hey! Any chance you could provide the full stack trace for this error (at least enough of it that I can see the call to .kept
that's causing this? It would give me a much better idea of the sequence of events that cause this.
Oh, just realized what it was. The undiscarded?
method is on master
but hasn't been released yet, so the rest of your code should work, but that predicate method doesn't exist. I'll have to cut a v1.2 here soon.
Thanks a ton for taking time to respond and explain!
v1.2 is out now!