Hi All,
I have some trouble using a alternative primary key in hobo:
I created a Rails 2.3.5 app (without hobo), with following models:
class Post < ActiveRecord::Base
belongs_to :user, :foreign_key => "user_code"
end
class User < ActiveRecord::Base
set_primary_key :code
has_many :posts
end
u = User.new
u.code = "USER1"
u.name="User 1"
u.save
u.find("USER1") => everything OK
p = Post.new
p.title = "Post 1"
p.user = u
p.save => OK, p.user_code == "USER1"
script/plugin install git://github.com/tablatom/hobo.git
add hobo to models, (hobo_model, fields) -> everything still ok, able
to add new post, assign user, etc.
Now I add a new model, group:
class Group < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
name :string
code :string
timestamps
end
set_primary_key :code
has_many :posts
end
and update the post model:
class Post < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
title :string, :default => ""
body :string, :default => ""
timestamps
end
belongs_to :user, :foreign_key => "user_code"
belongs_to :group, :foreign_key => "group_code"
end
now, when I create a new post, assign the user => fine, assign a group
=> save => group_code in post = 0
My conclusion is: models made without hobo work as expected, models
made using hobo give an issue.
Another thing: changing the primary key, causes the hobo_migration to
suggest to drop group.id. When group.id is dropped, I can't create a
new group, the group code is not saved.
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.