Topic: [SOLVED] Scopes and Many-to-Many checking
I have the following many to many relationship (using a relationships table).
#Eraser.rb has_and_belongs_to_many :pockets #Pencil.rb has_and_belongs_to_many :pockets #Pocket.rb has_many :pencils has_many :erasers
And of course I have my erasers_pencils table in the DB that links them together.
Now, when creating a "Pocket", you're able to select from a list of pencils and erasers. However, I would like to limit the list of pencils/erasers to only those that are "available" (not already assigned to a pencil/eraser).
I know that I'll need to add a scope to the pencil/eraser model, but how would I do this?
scope :available, where()
I need to make sure the pencils do not have an eraser assigned, and vice-versa.
Last edited by wesf90 (2012-02-17 21:30:06)