#84 ✓resolved
Jim

belongs_to associations not working for me

Reported by Jim | December 5th, 2007 @ 05:46 PM

#!/usr/bin/env ruby

require 'rubygems'
require 'data_mapper'

# add setup code here


User.auto_migrate!
Comment.auto_migrate!

class User < DataMapper::Base
  property :name, :string
  has_many :comments, :class => 'Comment', :foreign_key => 'user_id'
end
class Comment < DataMapper::Base
  property   :comment, :text, :lazy => false
  belongs_to :author, :class => 'User', :foreign_key => 'user_id'
end

u1 = User.create(:name => "u1")
p u1.comments
Comment.create(:comment => "c", :author => u1)
p u1.comments #=> should not be []
u1.reload!
p u1.comments #=> or at least, this should not be []

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages