Skip to content

Instantly share code, notes, and snippets.

@MichaelCPell
Last active August 29, 2015 14:04
Show Gist options
  • Save MichaelCPell/546e2a722682d87ce70d to your computer and use it in GitHub Desktop.
Save MichaelCPell/546e2a722682d87ce70d to your computer and use it in GitHub Desktop.
Your smallest next problem:
Make this command:
rails console$ Course.first.exercises
Produce (something like) this result:
>[{exercise 1 info}, {exercise 2 info}]
@andreadardon
Copy link

2.0.0-p247 :002 > Course.first.exercises
Course Load (4.8ms) SELECT "courses".* FROM "courses" ORDER BY "courses"."id" ASC LIMIT 1
Exercise Load (16.9ms) SELECT "exercises".* FROM "exercises" WHERE "exercises"."course_id" = ? [["course_id", 1]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Exercise id: 1, title: nil, body: "Primer ejercicio", course_id: 1, created_at: "2014-07-20 17:46:07", updated_at: "2014-07-20 17:46:07">, #<Exercise id: 2, title: nil, body: "Segundo ejercicio", course_id: 1, created_at: "2014-07-20 17:48:19", updated_at: "2014-07-20 17:48:19">]>
2.0.0-p247 :003 >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment