
belongs_to does not create the foreign-key property for Namespaced models
Reported by Postmodern | April 27th, 2008 @ 02:33 AM
The belongs_to association does not create the foreign-key property for models within a Namespace.
module Namespace
class Bird < DataMapper::Base
property :lol, :string
has_many :feathers
end
class Feather < DataMapper::Base
property :lol, :string
belongs_to :bird
end
end
Namespace::Bird.auto_migrate!
Namespace::Feather.auto_migrate!
$ sqlite3 test.db
sqlite> .schema
CREATE TABLE "namespace/birds" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "lol" TEXT);
CREATE TABLE "namespace/feathers" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "lol" TEXT);
Comments and changes to this ticket
-
Postmodern April 27th, 2008 @ 02:54 AM
Temporary work-around for DataMapper 0.3.1, manually add the foreign-key property to the model:
property :bla_id, :integer belongs_to :bla
-
Postmodern April 27th, 2008 @ 03:05 AM
Although the above work-around creates the needed columns, it does not fix the associations.
include Namespace bird = Bird.create(:lol => 'haha') bird.feathers << Feather.new(:lol => 'haha')
Produces:
NoMethodError: undefined method `instance_variable_name' for nil:NilClass from /usr/lib64/ruby/gems/1.8/gems/datamapper-0.3.1/lib/data_mapper/associations/belongs_to_association.rb:139:in `shallow_append' from /usr/lib64/ruby/gems/1.8/gems/datamapper-0.3.1/lib/data_mapper/associations/has_many_association.rb:135:in `<<' from (irb):27
-
Dan Sully April 30th, 2008 @ 12:51 PM
- Assigned user set to Sam Smoot
I am also having this issue.
A poor workaround is to remove the belongs_to and create methods manually.
-
Sam Smoot May 2nd, 2008 @ 04:28 AM
- Assigned user changed from Sam Smoot to Adam French
We'll give it a stab. Adam, please see what you can do about this. We'll fix up the DM 0.3.x associations real quick for that other work project for now so it'll be win/win for everyone...
-
Adam French June 3rd, 2008 @ 09:03 AM
- State changed from new to open
Is this still an issue? I notice the ticket is a month old with no follow up....
-
Dan Sully June 3rd, 2008 @ 10:19 AM
Unless there's been a new 0.3.x release that fixes it, yes it's still an issue.
-
-
Dan Sully June 4th, 2008 @ 10:11 AM
That's not the point. Some of us can't easily move to 0.9.x yet.
-
Adam French June 6th, 2008 @ 10:20 AM
- Assigned user cleared.
-
Sam Smoot June 11th, 2008 @ 11:46 AM
- Assigned user set to Adam French
- State changed from open to resolved
Resolved in 0.9.x. Happy to apply a patch for 0.3.x if anyone contributes one.
-
Adam French July 20th, 2008 @ 05:45 PM
- Tag set to associations, belongs_to, bug, namespace
since no patch was supplied, and this ticket hasn't seen an update since june, I'm gonna go ahead and mark it resolved. If you'd still like to see this happen, please reopen the 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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »