Ironruby and ActiveRecord

I wanted to try out IronRuby running rails.

I was following the
http://ironruby.net/Documentation/Real_Ruby_Applications/Rails tutorial
using the sqlite instructions.

I began writing my tests and found that I was not able to assign a
object to
a belongs to relationship and have it persist to the sqlite3 database
correctly. On investigation I found that the sql being generated did
not
have the correct ID. It was using .inspect instead of the value of the
ID
for my object.

Creation of the Post:
Post Create (31.3ms) INSERT INTO “posts” (“name”, “submitted_by”,
“phoned_in”, “category_id”, “completed_at”, “created_at”, “updated_at”)
VALUES(’’, ‘’, NULL, 0, NULL, ‘2010-05-18 10:59:32’, ‘2010-05-18
10:59:32’)

Looking up the category to assign:
Category Create (0.0ms) INSERT INTO “categories” (“name”,
“created_at”,
“updated_at”) VALUES(‘Cat 1’, ‘2010-05-18 10:59:32’, ‘2010-05-18
10:59:32’)

Assigning the post.category = category:
Post Request Update (15.6ms) UPDATE “posts” SET “category_id” = ‘
!ruby/object:System::Int64 {}
’, “updated_at” = ‘2010-05-18 10:59:32’
WHERE
“id” = ‘— !ruby/object:System::Int64 {}

Loading the post back from the db.
Post Load (0.0ms) SELECT * FROM “prayer_requests” WHERE
(“prayer_requests”.“id” = 1)
Category Load (0.0ms) SELECT * FROM “categories” WHERE
(“categories”.“id”
= 0)

As you can see above the ID is never set correctly and since sqlite just
jams strings into integer fields as 0 it tries to look up a category
with an
id of 0.

I was wondering if anyone has seen things like this in ActiveRecord with
IronRuby?

I’m running.
$ ir --version
IronRuby 1.0.0.0 on .NET 2.0.50727.3607

$ ir -S gem list

*** LOCAL GEMS ***

actionmailer (2.3.5)
actionpack (2.3.5)
activerecord (2.3.5)
activerecord-sqlserver-adapter (2.3.5)
activeresource (2.3.5)
activesupport (2.3.5)
rack (1.0.1)
rails (2.3.5)
rake (0.8.7)
sqlite3-ironruby (0.1.1)

If there is a better list to post to please let me know I’ll redirect my
question there.

Kevin

I figured out the issue.

It turns out that the sqlite3-ironruby adapter uses System::Int64 for
the
primary key column. This type is not checked for in the quoting logic
of
active record so it just serialize it into the yaml representation of
the
object.

I’ll need to dig into the sqlite source to correct the issue. There
must be
something up with the translation from .net types coming out of the DLL
to
ruby types.

kevin