softace / activerecord-tableless

Bringing together the different tableless model implementations into a single gem/plugin
Other
113 stars 41 forks source link

can't delete_all #14

Closed denwwer closed 10 years ago

denwwer commented 10 years ago

Rails 4 class MailerForm has_many Recipient and accepts_nested_attributes_for :recipients

example:

form = MailerForm.new(some_recipients_data)
p form.recipients
>> [#<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">, #             
<MailerForm::Recipient mailer_form_id: nil, email: "mail1@example.com">]

form.recipients.where(:email => "mail1@example.com").delete_all
p form.recipients
# got this
>> [#<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">, #             
<MailerForm::Recipient mailer_form_id: nil, email: "mail1@example.com">]
# instead of
>> [ #<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">]

so how I can do destroy ?

denwwer commented 10 years ago

fixed using next solution

form.recipients = form.recipients.to_a.reject!{|it| it.email == 'mail1@example.com'}
p form.recipients
>> [ #<MailerForm::Recipient mailer_form_id: nil, email: "mail2@example.com">]