ActiveRecord associations between tables with text fields fail
--------------------------------------------------------------
Key: JRUBY-3330
URL: http://jira.codehaus.org/browse/JRUBY-3330
Project: JRuby
Issue Type: Bug
Affects Versions: JRuby 1.1.6
Environment: Mac OS X 10.5.6, JRuby 1.1.6, Rails 2.1.2, MySQL 5.0
Reporter: Jeff Sutherland
Assignee: Thomas E Enebo
Priority: Blocker
Attachments: text_field_fun_day.tar.gz
Given two models and tables, with the parent having many children, and the
children belonging to the parent through ActiveRecord associations; and given
that the child table has a field with a type of :text, the association in of
parent.children is broken, as is the finder child.find_all_by_parent_id. The
results are given in script/console are gibberish, and no exception is shown in
development.log.
Take for example the attached sample Rails application.
class CreateDaddies < ActiveRecord::Migration
def self.up
create_table :daddies do |t|
t.column :field_1, :string
t.column :field_2, :string
t.timestamps
end
end
def self.down
drop_table :daddies
end
end
class CreateKiddies < ActiveRecord::Migration
def self.up
create_table :kiddies do |t|
t.column :daddy_id, :integer
t.column :field_1, :string
t.column :field_2, :text
t.timestamps
end
end
def self.down
drop_table :kiddies
end
end
class Daddy < ActiveRecord::Base
has_many :kiddies
end
class Kiddy < ActiveRecord::Base
belongs_to :daddy
end
class DaddyO
class << self
def test_everything
dad = Daddy.create(:field_1 => 'blah', :field_2 => 'blah')
kid = Kiddy.new
kid.field_1 = 'boogers'
kid.field_2 = <<EOF
BIG 32KB or so BLOB OF TEXT (see attached file)
EOF
kid.daddy_id = dad.id
kid.save
end
end
end
I then run this at the command line:
~$ jruby script/console
Loading development environment (Rails 2.1.2)
>> require 'daddy-o'
=> ["DaddyO"]
>> DaddyO.test_everything
=> true
>> d = Daddy.find(1)
=> #<Daddy id: 1, field_1: "blah", field_2: "blah", created_at: "2009-01-26
17:55:51", updated_at: "2009-01-26 17:55:51">
>> d.kiddies
=> [#<Kiddy id: 0, daddy_id: 0, field_1: "g here in the dark.\n He wants
that key. It is mi...", field_2: "the key too. All. He will ask fo",
created_at: nil, updated_at: nil>]
>> k = Kiddy.find_by_daddy_id(1)
=> #<Kiddy id: 0, daddy_id: 0, field_1: "g here in the dark.\n He wants that
key. It is mi...", field_2: "the key too. All. He will ask fo", created_at:
nil, updated_at: nil>
I clear my database. I then run the same code against regulary Ruby 1.8.6.
~$ ruby script/console
Loading development environment (Rails 2.1.2)
>> require 'daddy-o'
=> ["DaddyO"]
>> DaddyO.test_everything
=> true
>> d = Daddy.find(1)
=> #<Daddy id: 1, field_1: "blah", field_2: "blah", created_at: "2009-01-26
17:55:51", updated_at: "2009-01-26 17:55:51">
>> d.kiddies
=> [#<Kiddy id: 1, daddy_id: 1, field_1: "boogers", field_2: " --The rage of
Caliban at not seeing his face in...", created_at: "2009-01-26 17:55:51",
updated_at: "2009-01-26 17:55:51">]
>> k = Kiddy.find_all_by_daddy_id(1)
=> [#<Kiddy id: 1, daddy_id: 1, field_1: "boogers", field_2: " --The rage of
Caliban at not seeing his face in...", created_at: "2009-01-26 17:55:51",
updated_at: "2009-01-26 17:55:51">]
>> exit
Note that under JRuby 1.1.6, the association returns kiddy_id of 0, daddy_id of
0, and a scramble of field_1 and field_2. This is a blocking issue because I
need two tables with text fields to be associated with each other without
errors. It works under Ruby, but not JRuby.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email