Forum: Ruby on Rails has_one :through saving

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wouter d. (Guest)
on 2009-05-28 13:28
Hi all,

I'm having issues with a has_one :through relationship. I have a setup
where "Ticket has_one :show, :though => :pool". The thing worked, but
what I noticed is that as soon as my ticket is saved, the show is also
saved. In my case this is pretty dangerous, since I'm using optimistic
locking on the show and since tickets are updated very frequently,
things can get pretty messy.

Is it possible to turn of this behavior and never save the associated
model? In my case, the show is never set directly on the ticket
( = Show.find(x) is never done), so I've worked around it by
just creating a method "show" that returns, but I don't really
like this solution, since I also use the relation in some API code that
figures out what to return by inspecting the model.


Brian (Guest)
on 2009-05-28 18:10
(Received via mailing list)
Does :autosave do what you want?

has_one :show, :though => :pool, :autosave => false

Or if you never want to save this way, maybe:

has_one :show, :though => :pool, :readonly => true

I haven't tried either, but I remember running across these in one of
the rails guides, so maybe it helps.

On May 28, 5:28 am, Wouter de Bie <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.