#548 ✓resolved

potential bug in saving records with associations?

Reported by Fabian | September 3rd, 2008 @ 08:29 AM

When I do:

>> @course= Course.new(:title=>"asd")
=> #<Course id=nil title="asd">
>> @task = Task.new
=> #<Task id=nil title=nil deadline=nil>
>> @task.course = @course
=> #<Course id=nil title="asd">
>> @task.save
=> true

course as well as task is saved in the database, but course_id field in tasks is empty. I have to save the course first then do the @task.course = @course so course_id is filled. When I save @course before saving @task, @task.course points to the saved @course with filled id in it, but when I do @task.save tasks.course_id isn't filled.

My Models:

## Model Course
class Course
  include DataMapper::Resource

  property :id, Serial
  property :title, String

  has n, :tasks

## Model Task
class Task
  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :deadline, DateTime

  belongs_to :course

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