Ali   [got your mail 6 days later for some reason]

1)  first remember that in Ruby  "<<" is the "append" operator, eg:

   p = [ 3 ]
   p << 1 << 4   # => [3, 1, 4]

2) now in ActiveRecord

post1       = Post.create(..)          # this must be saved in db
comment = Comment.create(..)  #            ,,
post1.comments << comment

This is more than adding 'comment' to the list; *it is linking back the
foreign key of comment back to post1*. So that the next time you do:

   post1 = Post.find(...)
   post1.comments.each { |comment| ... }

it will be able to find all the comments of post1.

Raul


On Tue, Dec 2, 2008 at 10:10 PM, alibaba82 <[EMAIL PROTECTED]> wrote:

>
> class CreateTestData < ActiveRecord::Migration
>  def self.up
>    down  # Delete all rows from the posts and comments tables
>
>    post1 = Post.create(:id => 1, :title=> "First title", :body=>
> "This is the body of the first posting")
>
>    comment = Comment.create(:id => 1, :comment=>"What a boring
> posting. Can you do better next time? - Sang Shin")
>    post1.comments << comment
>
>
> I dont understand the following line
>  post1.comments << comment
>
> What does '<<' do
>
> Thanks
>
> Ali
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to