
Associations don't work if the FK property is private / protected
Reported by Carl Lerche | January 15th, 2009 @ 01:42 PM
The following does not work:
Setting FKs as private is needed to protect them against mass assignment, but then association code does not work. See the following example.
#!/usr/bin/env ruby -KU
require "rubygems"
require "dm-core"
class User
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :comments
end
class Comment
include DataMapper::Resource
property :id, Serial
property :user_id, Integer, :accessor => :private
property :body, String
belongs_to :user
end
DataMapper.setup(:default, "sqlite3::memory:")
DataMapper.auto_migrate!
user = User.create(:name => "Carl")
user.comments.create(:body => "Hello World")
comment = Comment.first
puts "#{comment.user.name} said: #{comment.body}"
Comments and changes to this ticket
-
Dan Kubb (dkubb) January 15th, 2009 @ 01:46 PM
- State changed from unconfirmed to confirmed
-
Dan Kubb (dkubb) May 28th, 2009 @ 03:59 AM
- State changed from confirmed to resolved
I can confirm this is now resolved in dm-core/next.
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »