Skip to content

Instantly share code, notes, and snippets.

@pramatias
Created January 12, 2011 13:31
Show Gist options
  • Save pramatias/776163 to your computer and use it in GitHub Desktop.
Save pramatias/776163 to your computer and use it in GitHub Desktop.
#app/models/chatter.rb
class Chatter < ActiveRecord::Base
has_one :chats
end
#app/models/chat.rb
class Chat < ActiveRecord::Base
belongs_to :chatter, :foreign_key => 'chatter_id'
end
#irb queries
>> c = Chat.find(:first, :conditions => ["chatter_id =2"])
=> #<Chat id: 1, chatter_id: 3, created_at: "2011-01-11 16:27:16", updated_at: "2011-01-11 23:27:34">
>> r = Chatter.find(:first, :conditions => ["id = #{c.chatter_id}"])
=> #<Chatter id: 2, name: "asfdsad", created_at: "2011-01-11 18:41:41", updated_at: "2011-01-11 18:41:41">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment