STI support is still under construction, so you may hit some rough spots. 

That said, there are some ways to clean up the associations you've got. See 
below.

On Nov 10, 2011, at 9:16 AM, AncientHobo wrote:

> Hi,
> Been working through the book. Find this really fascinating
> considering how much time I can save in future. Relatively new to Ruby/
> Rails. Very new to Hobo. I shall appreciate if you could comment/
> assist with what I am trying to do do.
> 
> I have two models (see) below.
> All's fine with migrate and the database but how do I get this to play
> on forms.
> 
> 
> class Shipment < ActiveRecord::Base
> 
>  hobo_model # Don't put anything above this
> 
>  fields do
>    no :string
>       fname :string
>       lname :string
> 
>       phone :string
>       mobile :string
>       fax :string
>       email :string
> 
> 
>    timestamps
>  end
> 
>  has_one     :physical_address, :dependent => :destroy, :as
> => :addressable, :class_name => "Address", :conditions =>
> "address_type = 'Physical'"

Two thoughts on this:

- Rails should do the type condition for you if you write this as:

has_one :physical_address, :dependent => :destroy, :as => :addressable

assuming you have a class:

class PhysicalAddress < Address
end

- it may make more sense to put the foreign key here, rather than on Address. 
This allows Address records to be reused for multiple Shipments, *and* avoids 
the complications that polymorphic associations bring.

It would look like:
class Shipment < ActiveRecord::Base
  ...
  belongs_to :physical_address
  ...etc
end

class PhysicalAddress < Address
  has_many :shipments
end

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
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.

Reply via email to