On 4/21/08, codex1 <jfagan365-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have three models:
>
> 1) employees
> has_many :memberships
> has_many :projects, :through => :membership
>
> 2) projects
> has_many :memberships
> has_many :employees, :through => :membership
>
> 3) membership
> belongs_to :employees
> belongs_to :projects
>
> Membership is used to join employees to projects.
>
> In my projects_controller I have a method called
>
> def disassociate_employee(employee_id)
> end
>
> In this function I want to somehow delete the database row in
> membership that joins employees t o projects.
>
> I have no idea how to do this and has so far spend two full days
> trying to figure this out, but starting to go a bit crazy trying to
> figure this one out. :-)
Membership.find_by_employee_id_and_project_id( employee_id, project_id
).destroy rescue nil
Or rewrite the find to use :conditions if you don''t trust the source
of your employee and project ids.
--
Greg Donald
http://destiney.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---