On 2008-12-03T22:14:00, makoto kuwata <[EMAIL PROTECTED]> wrote:
> How to reload associated models?

I found that dept.employees.reload is the solution.

thanks.

--
regards,
makoto kuwata


On 2008-12-03T22:14:00, makoto kuwata <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a question about association.
> How to reload associated models?
> I destroyed a model object, but it is remained in an association.
>
> For example:
>
>     ## create department and employees
>     dept = Department.create!(:name => "Sales")
>     emp1 = Employee.create!(:name => "John", :department => dept)
>     emp2 = Employee.create!(:name => "Mike", :department => dept)
>     dept.employees    #=> [emp1, emp2]
>
>     ## an employee is destroyed
>     emp1.destroy
>
>     ## but it is not removed from dept.employees
>     dept.employees    #=> [emp1, emp2], OH NO!
>
>     ## after removing '@employees_assciation', dept.employees works
> fine
>     dept.instance_variable_set('@employees_association', nil)
>     dept.employees    #=> [emp2]
>
> Setting '@employees_association' to nil makes an association
> to reload new values, but I think that this is not good solution.
> Could you help me?
>
> --
> regards,
> makoto kuwata
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to