I have Employee and Skillset which are joined through an Association employees_skillsets. When I use the for to add a new employee and mapping one or more id''s from skillset into employee_skillset_ids everything works. Where I have issues is in two places 1. When I destroy an employee or a skillset the associated records are not automatically removed from employees_skillsets 2. How do I create an assocoation in the console.>> @employee = Employee.find(:first)=> #<Employee id: 100, >> @skillset = Skillset.find(107) => #<Skillset id: 107, ">>> @employee.skillsets[0] = @skillset=> #<Skillset id: 107, >>> @employee.save=> true Does not work.>> @employee.skillset_ids=> [] What is the form doing?>> @employee.skillset_ids[0] = 107=> 107>> @employee.skillset_ids=> [] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 9, 2008, at 10:56 AM, Jorg Lueke wrote:> I have Employee and Skillset which are joined through an Association > employees_skillsets. When I use the for to add a new employee and > mapping one or more id''s from skillset into employee_skillset_ids > everything works. Where I have issues is in two places > > 1. When I destroy an employee or a skillset the associated records are > not automatically removed from employees_skillsets > > 2. How do I create an assocoation in the console. > >>> @employee = Employee.find(:first) > => #<Employee id: 100, >> > @skillset = Skillset.find(107) > => #<Skillset id: 107, "> >>> @employee.skillsets[0] = @skillset > => #<Skillset id: 107, > >>> @employee.save > => true > > Does not work. > >>> @employee.skillset_ids > => []Have you tried: >> @employee.skillsets << @skillset> What is the form doing? > > >>> @employee.skillset_ids[0] = 107 > => 107 >>> @employee.skillset_ids > => []-Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What worked is employee = ... skillset = ... employeeskillset EmployeesSkillset.new(:employee=>employee, :skillset =>skillset) employeeskillset.save I did now know about this extra object. I tried your suggestion and that works as well! Cool, thanks. On Jul 9, 10:04 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jul 9, 2008, at 10:56 AM, Jorg Lueke wrote: > > > > > I have Employee and Skillset which are joined through an Association > > employees_skillsets. When I use the for to add a new employee and > > mapping one or more id''s from skillset into employee_skillset_ids > > everything works. Where I have issues is in two places > > > 1. When I destroy an employee or a skillset the associated records are > > not automatically removed from employees_skillsets > > > 2. How do I create an assocoation in the console. > > >>> @employee = Employee.find(:first) > > => #<Employee id: 100, >> > > @skillset = Skillset.find(107) > > => #<Skillset id: 107, "> > >>> @employee.skillsets[0] = @skillset > > => #<Skillset id: 107, > > >>> @employee.save > > => true > > > Does not work. > > >>> @employee.skillset_ids > > => [] > > Have you tried: > >> @employee.skillsets << @skillset > > > What is the form doing? > > >>> @employee.skillset_ids[0] = 107 > > => 107 > >>> @employee.skillset_ids > > => [] > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---