Ok not exactly a Hobo specific question but I'm hoping someone here can help
me out.
I have the following model
class Sample < ActiveRecord::Base
hobo_model # Don't put anything above this
SAMPLE_TYPES = HoboFields::Types::EnumString.for(:asbestos, :lead, :pcb)
fields do
sample_type Sample::SAMPLE_TYPES
positive :boolean
result :string
timestamps
end
inline_booleans true
belongs_to :material
belongs_to :location, :class_name => "LocationMaterial", :foreign_key =>
:location_id, :conditions => ["location_materials.material_id = ?", 2]
...
end
As you can see the conditions are hard coded to material_id 2. What I want
is the ID of the material belongs_to association. I know this looks a bit
confusing as to why I would want that so I'll try to explain.
Locations have many materials and materials have many locations, classic
many_to_many through locations_materials
Materials have many samples and sample belong to materials.
So far pretty straight forward.
Now samples also need to be tied back to the location they where taken from
IE I need to know not only what material was samples but where it came
from. I also need to restrict the location selection list when
adding/editing samples to only locations where the material exists. Can't
sample a material where it doesn't exist after all.
Perhaps I'm barking up the wrong tree here, I've done that before so I'm
open to other sugestions but it looks to me as Hobo will handle the
restriction quite nicely if I can get the condition on the belongs_to to
work.
Bob
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/hobousers/-/tkHz7q3slXMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.