Wins Lin <[email protected]> wrote:
> tamouse m. wrote in post #1111882:
> 
> > see the author_name up there?
> >
> > When you save the post, that's when it calls the #set_author method,
> > which either finds an existing author with the name given, or creates a
> > new one, which is connected to the new post record with self.author.
> 
> It has been quite a break-through for me today :)
> I used to do queries step by step, one by one, outside of model and then
> assemble results together in one final Mode.create/save() method. All is
> done in transaction but outside a model.
> 
> But isn't it strange, isn't it quite illogical that one model is
> responsible for creating an absolutely different other model? In this
> example the Post model is responsible for creating an instance of the
> User model. And more than that, all the logic of creating a new User
> instance is located inside of the Post model. It is against the idea of
> AR pattern where each model is responsible for its own behavior.
> 
> But it is a rhetorical question from me. The way Rails offers do save
> objects is pretty convenient. I'm glad I've understood it today.
> 
> 
> > You *can* do it the other way around, but it's clearly more work, since
> > ActiveRecord/Arel is doing all that for you.
> 
> I should read more about this Arel feature.

* http://guides.rubyonrails.org/association_basics.html
* http://guides.rubyonrails.org/active_record_querying.html

I haven't really gone through them to find the differences, but you can
also look at the edgeguides version of those pages, too. Very helpful,
as are all the guides, with deep reading and re-reading. I tend to learn
something knew each time I go through them.

> Thank you.


My pleasure. :)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/51b67fea.e6a4320a.7820.5cd4%40mx.google.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to