On Oct 7, 10:22 am, Bjoern <[email protected]> wrote:
> > I'm not quite sure what you're saying. Instead of doing User.new, try
> > to find an appropriate User record first.
>
> I'd like to avoid that, to keep the part of the code clean from
> database access. I create a DirectMessage with two associated Users
> and then only call DirectMessage.save
>
> I suppose I could check all the Users before doing the save, but it
> would create a lot of clutter (compared to one line of executing
> save). I was hoping there would be a more elegant way.
>
> The API docs for save sound as if they would create or update, so
> maybe the question is how do they decide what is new and what needs
> updating.
If you do User.new you will always get a new object that AR will then
try to insert.
Sounds like you would also get an error whenever you handle a message
to / from a user you have already handled a message from.
Fred
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---