--
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/-/D5UF91irwdQJ.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
I'm not following what you're going for here - has_one doesn't create a foreign key, especially not a :through...
A more typical way to describe this would be either with belongs_to:
class Organization < ActiveRecord::Base
...
belongs_to :primary_contact, :class_name => 'User'
end
This will give you a select-one on the forms for organization - but it won't automatically scope the selection to the :users association, and will need some extra logic to handle the "primary contact manually deleted leaving invalid primary_contact_id" situation.
An alternative would be to define a flag on User:
class User < ActiveRecord::Base
fields do
...
primary_contact :boolean, :default => false
end
end
And then a has_one association with conditions:
class Organization < ActiveRecord::Base
...
has_one :primary_contact, :class_name => 'User', :conditions => { :primary_contact => true }
end
You'll need some custom views and/or model logic to ensure that you've only got one selected at any given time.
--Matt Jones
The biggest reason is "because nobody implemented it", but the other
reason is that internally in Rails, has_one is basically a has_many
that's constrained to having 1 child, and has always been the ugly
stepchild. By now I'm sure most of the warts have been cleaned up
but certainly at some points in time it has had problems.
Bryan
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.