Join Association Question

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
=> []

On Jul 9, 2008, at 10:56 AM, Jorg L. wrote:

@employee = Employee.find(:first)
@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 B. http://agileconsultingllc.com
[email protected]

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 B. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs