Yes the model is pretty much like that.
class OldClaimPart < ActiveRecord::Base
set_table_name :P
set_primary_key :P_ID
end
I'm just wondering if it is something to do with there being a column
called ID as well as a primary key P_ID?
What seems strange to me is that the generated SQL that is causing the trouble is
trying to insert a NULL value to the auto-generated P_ID column.
Presumably, based on the error message this isn't possible for SQL server.
I tried the following statements in a SQL Server query window and the first one failed,
the latter one inserted fine.
INSERT INTO [P] ([P_ID], [ID], [P_ClaimNo]) VALUES(NULL,N'xv23254752102', N'23254752102')
INSERT INTO [P] ( [ID], [P_ClaimNo]) VALUES(N'xv23254752102', N'23254752102')
I'm wondering what you mean when you say the DB is not doing what it should?
If you're saying SQL Server is not behaving as you may expect it to, then shouldn't
that mean that something in the adapter should be altered so that it communicates
in an expected manner?
Unless you were thinking I'd ommited the set_table_name and set_primary_key?
It seems to me that ActiveRecord or sqlserver-adapter (or at whatever level it occurs in the callstack)
should be using the second type of query when there is an auto-incremented primary key.
I could well be wrong though, so if you have any pointers to how to workaround/fix this, I'd be
grateful.
> had thrown an error I would have spotted it.
> Presumably this does something unlike what I was expecting.
Yea... I've seen this trip people up before (including me). What you
did there was just create a local variable to the class. It is common
that if you want to call the whatever= method in scope at the time vs
creating a local variable you will need to either prefix with self. or
use the long winded setter method. For example, setting bar would not
have hit the accessor unless I used self.
class Foo
attr_accessor :bar
def validate
self.bar = 'batz'
end
end
f = Foo.new # => #<Foo:0x100174688>
f.validate
f # => #<Foo:0x100174688 @bar="batz">
> By the way the reason for the discrepancy is because last night I
> was at home and not in front
> of the code at work. In my mind primary_key= and set_primary_key
> were obviously equivalent.
No worries. I had a feeling.
> I did have to do a _lot_ of hacking to get Windows and Ruby 1.9.1
> playing nicely with Sql Server and the
> various other gems I wanted to use (most difficult being Cucumber).
>
> I will try and get back to you with more details of problems I
> encountered. I'm not 100% clear at this
> point what things worked and didn't work as I spent around a week
> battling with the installation
> process, but I know I defintely had some problems with ODBC/DBI/SQL
> Server. But don't understand
> enough to know what the root cause of the various problems were.
>
> Most of my searches were either no results or one that didn't help,
> so I imagine I may be
> one of the lucky few to get it working and may have useful
> knowledge. Unfortunately(?), I don't have
> windows at home and so can't do a lot in my spare time.
Well if you do find some time, please help us out and put something up
on the wiki. I added an article there this week that covered getting
Ruby Enterprise Edition (REE) up and running with this stack. Would
love to know more about Windows setup. I have a goal in my head that I
want to try out IronRuby for the hell of it and see if I can do some
stuff to either show up or help for the next upcoming RubyConf. As a
side note, if anyone is on the list from the IronRuby team, I kept
hearing from ya'll with native connection additions to the adapter and
no one gets in touch with me afterward. What up ya'll????
- Cheers,
Ken