Destroy association in memory

159 views
Skip to first unread message

Anatoliy Lysenko

unread,
Jul 22, 2010, 7:42:54 AM7/22/10
to Ruby on Rails: Talk
Hi,
Does Rails antipode of build method?
Build make object in memory, and save it to database when parent
object is saved.
I need method to destroy object in memory and remove it from database
when parent object is saved.
mark_for_destruction is not the answer, because it not destroy object,
only mark it.

Thanks,
Anatoliy.

Bill Walton

unread,
Jul 22, 2010, 8:57:23 AM7/22/10
to rubyonra...@googlegroups.com
Hi Anatoliy,

On Thu, Jul 22, 2010 at 6:42 AM, Anatoliy Lysenko <a.o.l...@gmail.com> wrote:
> I need method to destroy object in memory and remove it from database
> when parent object is saved.

The notion of children that exiss prior to the parent's creation is a
bit odd, but assuming that you have some way to identify them other
than session variables, you could use an after_create method in your
parent model to destroy the child objects.

HTH,
Bill

Anatoliy Lysenko

unread,
Jul 26, 2010, 9:42:53 AM7/26/10
to rubyonra...@googlegroups.com
Hi Everyone,
Thanks for responses,
 I found what I need: http://rails.lighthouseapp.com/projects/8994/tickets/4521-habtm-ability-to-link-and-unlink-records-with-autosave-true


Thanks,
Anatoliy.

2010/7/22 Colin Law <cla...@googlemail.com>
On 22 July 2010 14:28, Anatoliy Lysenko <a.o.l...@gmail.com> wrote:
> Hi Bill,
> I was not clear,
>
> Given situation when we have parent object task, and child object resource,
> task has many resources.

Is that also resource belongs_to task?

> When user edit task, change some fields, delete some resource association,
> add some resource association
> Notice than user not create resource or task, it create only association
> task <-> resource

So you are just setting the id field in an existing resource in the db?

> Then user save task
> And task is not saved due to validation error
> Then changed fields is changed in memory, not database
> Then for added resource association builded in memory, not in database

What do you mean the association is built in memory?  Also nothing is
saved in memory from one request cycle to the next, so I do not
understand what you are trying to say.

Colin

> #the issue is here
> Then for deleted association to resource we have two choices:
> delete association to resource both in memory and database
> or
> mark it for destruction and have it both in memory and database
>
> I need:
>  destroy association to resource in memory, not in database, and destroy
> association in database only when task saved
>
> Something like mark_for_destruction, but when you mark object it is still in
> association.
>
>
> Thanks,
> Anatoliy
>> --
>> 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 rubyonra...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> rubyonrails-ta...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>
>
> --
> 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 rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>

--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply all
Reply to author
Forward
0 new messages