I have a sticky problem and feel my knowledge of SQL is coming short.
Basically I have two Models, Foo and FooTracker. Foo hass_many
FooTrackers and FooTracker belongs_to Foo. So FooTracker has a field
foo_id.
At some point I have a FooTracker ID(which is not unique in the
foo_trackers table) and want to serve the next Foo which is NOT
already associated with a FooTracker. I have no idea how to do this. I
can of course do some thing like(not sure if it’s syntaxtacilly
correct):
def find_next(footracker_id)
trackers = FooTracker.find_all_by_footracker_id(footracker_id)
Foo.find_all.each do |foo|
if trackers.foo_id.include?(foo)
return foo
end
end
end
But that seems a bit of a waste. Especially since I’ll have to do this
very often. Does any one have a better suggestion? The DB schemas are
also not yet fully determined so perhaps there is room for
optimazation there as well.