views:

29

answers:

1

How do I return the object after a model save like:

      Message.new(:receiver => receiver, :sender => self, 
      :subject => subject,
      :body => body).save

I understand I could probably do a

      Message.last

But will there be any implications during a high traffic time period where the database is constantly being accessed? I'm afraid that Message.last will return another record.

+1  A: 

If you're directly creating the object, you can use the create method, which creates and returns it.

message = Message.create(...)

It does the same then what's suggested by DR. But in only one code line :)

Damien MATHIEU