does hobo understand how to display a has_many through relationship?
I’m trying to add a association of many lots per user.
class Lot < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
number :integer
code :string
timestamps
end
has_many :lots_users
has_many :users, :through =>'lots_users', :foreign_key =>'user_id'
.....
class User < ActiveRecord::Base
hobo_user_model # Don't put anything above this
fields do
name :string, :required, :unique
email_address :email_address, :login => true
administrator :boolean, :default => false
timestamps
end
has_many :lots_users
has_many :lots, :through =>'lots_users', :foreign_key => 'lot_id'
....
class LotsUsers < ActiveRecord::Base
belongs_to :user
belongs_to :lot
end Discussion
-
yes it does understand. i think you need to update your viewhints files…
in user_hints.rb put…
children :lotsand in lot_hints.rb put
children :usersand possibly
has_many :users, :through =>'lots_users', :foreign_key =>'user_id', :accessible => trueor
has_many :lot_users, :accessible => trueviewhints children will work for the show pages. To be able to modify associated models through the new and edit forms, you need to tell the model that the association itself is accessible from the model that should be able to create/edit the association. Once you do that, the forms will update with a default multi-model form that should be good for common use cases.
Depending on which association is accessible will change the behavior of the form. If the join model (in this case, the
lot_users), you will be able to create links to the existing lots, or users depending on which model you’re accessing from, but not new users or lots. If you put the accessible on thehas_many ...,:through => ...association, you’ll be able to create new records from the user (or lot) new and edit forms. -
http://cookbook.hobocentral.net/manual/viewhints
http://cookbook.hobocentral.net/manual/multi_model_forms
the relevant manual pages for viewhints and accessible associations respectively.