I have a code that looks like this:
*movie_requests is a scope
def self.records (producer_id = 0)
actor_list = Array.new
movie_requests(producer_id).find_each do |studio|
actor = studio.actors.pluck(:id).uniq
if (!actor_list.include? actor) && (!actor.nil?)
actor_list << actor
end
end
return actor_list
end
Originally in the database, it has these actor ids:
[[12305], [3749], [1263], [], [], [1263], [], [12305], []]
.pluck and .uniq makes redundant ids from each studio distinct however []
still exists:
[[12305], [3749], [1263], []]
Why doesn't my && (!actor.nil?)
condition catches the null ids and make it a distinct object?
Aucun commentaire:
Enregistrer un commentaire