# Ironruby and ActiveRecord

**URL:** <https://www.ruby-forum.com/t/ironruby-and-activerecord/188785>\
**Category:** IronRuby\
**Created:** [May 18, 2010, 1:40pm UTC](https://www.ruby-forum.com/t/ironruby-and-activerecord/188785 "2010-05-18T13:40:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Pratt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9bcb4/32.png) [@Kevin\_Pratt](https://www.ruby-forum.com/u/Kevin_Pratt)\
**Post date:** [May 18, 2010, 1:40pm UTC](https://www.ruby-forum.com/t/ironruby-and-activerecord/188785/1 "2010-05-18T13:40:28Z")

</div>

I wanted to try out IronRuby running rails.

I was following the  
[http://ironruby.net/Documentation/Real\_Ruby\_Applications/Rails](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

---

<div class="post-metadata">

**Author:** ![Kevin\_Pratt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9bcb4/32.png) [@Kevin\_Pratt](https://www.ruby-forum.com/u/Kevin_Pratt)\
**Post date:** [May 19, 2010, 3:16pm UTC](https://www.ruby-forum.com/t/ironruby-and-activerecord/188785/2 "2010-05-19T15:16:45Z")

</div>

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
