I'm working on a method but the results are "the opposite" of what I
want to happen. Here's what I have in my model:
after_update :foo
def foo
self.scores.where(:standard_id => self.standard_ids).each do |
score>
score.destroy
end
end
... which actually deletes the scores I want to keep. What I want to
do is something like:
self.scores - self.scores.where(:standard_id =>
self.standard_ids).each do...
OR
a = self.scores
b = self.scores.where(:standard_id => self.standard_ids)
a - b = c
c.each do...
OR
self.scores.reject(self.scores.where(:standard_id =>
self.standard_ids)).each do...
Any help is greatly appreciated! Thanks in advance
Ammar_Ali
(Ammar Ali)
5 November 2010 06:56
2
I'm working on a method but the results are "the opposite" of what I
want to happen. Here's what I have in my model:
<snip>
Any help is greatly appreciated! Thanks in advance
If an extra query is not too expensive for your situation, how about:
scores.where(["standard_id NOT IN (?)", standard_ids])
Do you really need self in those statements?
Hope that helps,
Ammar
···
On Fri, Nov 5, 2010 at 6:20 AM, DemetriusOlsen <demetriuso@hotmail.com> wrote:
Ammar,
If an extra query is not too expensive for your situation, how about:
scores.where(["standard_id NOT IN (?)", standard_ids])
This worked! Thank you! At this point, I'm glad it worked and have no
idea how to tell if it is "too expensive." Can you recommend a
resource that provides more info?
Do you really need self in those statements?
Just searched for more info about when to use self (or not) and came
up with this advice: "Never use self for retrieving values, since it’s
unnecessary and adds bulk. ...in the context of ActiveRecord."
http://bit.ly/cVgYK This was helpful too:
http://paulbarry.com/articles/2008/04/17/the-rules-of-ruby-self
Thanks again for your help.