update on a m:n table

0 views
Skip to first unread message

Christoph Thommen

unread,
May 10, 2008, 2:54:38 PM5/10/08
to rubyonra...@googlegroups.com
Hi all

following situation:
3 tables:
users (id, nickname,...)
conversations(id, ...)
conversations_users(user_id, conversation_id, date_deleted)

2: models
user (has_and_belongs_to_many :conversations,
:join_table=>'conversations_users', :conditions=>'date_deleted IS NULL')
conversation

How can i update update the "date_deleted" in the m:n join table? If i
want to do it by
user.conditions.date_deleted = DateTime.now

it don't work


Any idea?

Greets
--
Posted via http://www.ruby-forum.com/.

Rails Terrorist

unread,
May 10, 2008, 3:45:02 PM5/10/08
to rubyonra...@googlegroups.com
I dont like this way, but this is my answer :

for sample in user.conditions
sample.date_deleted = DateTime.now
end

but it will hurt your AR or database because it will connect to database
for each looping. Maybe another have lovely solution.

Reinhart
http://teapoci.blogspot.com

Reply all
Reply to author
Forward
0 new messages