On 8.2.2005, at 16:28, John Johnson wrote:>
> app/models/ecr.rb
> class Ecr < ActiveRecord::Base
> belongs_to :requester, :class_name => ''User'',
:foreign_key =>
> ''requester_id''
> belongs_to :part
> belongs_to :level
> has_and_belongs_to_many :approver, :class_name =>
''User'',
> :foreign_key => ''approver_id''
> end
>
This should help:
has_and_belongs_to_many :approvers, :class_name => ''User''
>
> app/models/user.rb
> class User < ActiveRecord::Base
> has_many :ecrs, :class_name => "User", :foreign_key =>
"requester_id"
You can''t use symbol :ecrs twice here. Change either of them, e.g like
this:
has_many :requestees, :class_name => "Ecr", :foreign_key =>
"requester_id"
(here you have to assign the :class_name explicitly because your
association name (:requester) is not the same as the class name
("Ecr"). However, it should be the other side of the association, i.e.
Ecr, not User)
> has_and_belongs_to_many :ecrs, :class_name => "User",
:foreign_key
> => "approver_id"
has_and_belongs_to_many :ecrs
(you don''t need to specify anything else. :class_name =>
"User" is
plain wrong, it should be Ecr. However, you can leave it away since
rails can guess the name from ":ecrs". Foreign key means the foreign
key in ecrs_users table that refers to users table. As it is user_id,
you don''t have to say it explicitly)
Other way would be to use this:
has_and_belongs_to_many :approvees, :class_name => "Ecr"
Now your ecrs_users table can be as simple as
ecr_id int
user_id int
> Eventually, the Users table will (I hope) be filtered based on fields
> like can_approve and can_request, so that only
> can_approve=1 Users can approve, etc.
>
> Is this the proper way to do this?
> It seems a bit kludgey since the ecrs_users table is doing double duty.
Shouldn''t do anymore. Hope you can get something off my hieroglyphs. If
not, drop a line or step into #rubyonrails on irc.freenode.net.
//jarkko
>
> Thanks for any advice!
>
> Regards,
> JJ
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Jarkko Laine
http://jlaine.net
http://odesign.fi
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails