Closed markmcdonald51 closed 13 years ago
affilitiations model has many attributes or is it just a group_id and user_id table?
class Affiliation < ActiveRecord::Base belongs_to :user belongs_to :company belongs_to :group end
If you could remove company from Affiliation you could change it to a has_and_belongs_to_many association which is writeable.
If not it s get a little bit more complex, cause through assocations are by design read only associations in activerecord, which means you can only edit/create has_many association to affiliations.
So one option would be to define to_label method of affiliation model to show the user?
If you don t like that because to_label will be used everywhere you might create a custom form column helper for that association, where you show user name in select box.
Yeah. It is actually a bit more than that. As the table definition is probably going to get a bit more hairy in the future (maybe adding in aasm states and such). At present it looks like:
create_table :affiliations do |t| t.references :user t.references :company t.references :group t.string :role
I really like using Active Scaffold for some stuff but the problem is when you need to add in something complex it gets a little scruffy. I was using AS for some pretty large stuff where we had to use a hack saw to get it to do the right thing. It's a great tool for prototyping --nice and easy to look at simple data.
Thanks for the response.
Well, you are most definetly right, that complex stuff remains complex even with Activescaffold... :-)
However, I think rails 3 version improves this at least in some areas and I would nt call a form override complex.
So wait, you're saying I could just create a form override and use the :through association?
You're right. This isn't complex but it does need to be a :through association which I thought was unsupported by AS (right?). So if I did create the form override for :users would it even update on the backend?
Nope, you are right I ve mixed that up with another use case. Let me think about this for a few days. Through associations are on my open feature list.
Hi,
I noticed that :through associations such as :users (listed below) are not available in an update as these are designated read_only. Is there anyway around this if I wanted to create a select list using this through assoc?
class Group < ActiveRecord::Base belongs_to :company has_many :affiliations has_many :users, :through => :affiliations end
Thanks in advance. Mark