rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
972 stars 557 forks source link

Can I query to views? #131

Closed drobazko closed 12 years ago

drobazko commented 12 years ago

Hi! )

I'm under Windows XP. MSSQL 2005 Ruby 1.9.2 RoR 3.0.9 activerecord-sqlserver-adapter 3.0.15 Tiny-TDS

I created a view named Inv_first_materials on my some table. Also I created a model:

class Inv_first_material < ActiveRecord::Base
end

I tried to execute a query:

Inv_first_material.select("id").where(["code=1202"])

But I get error:

_ActiveRecord::StatementInvalid: TinyTds::Error: Invalid object name 'inv_first_materials'.: SELECT [inv_first_materials].id FROM [inv_firstmaterials] WHERE (code=1202)

Can I query to views via activerecord-sqlserver-adapter and tiny-tds?

Thanks

drobazko commented 12 years ago

Of course, I can sorry for question, I have no appropriate experience yet ))

metaskills commented 12 years ago

LOL, that's OK. Just keep with convention and idiomatic ruby and things will work out better. Make your table name [inv_first_materials] for the name. Notice the underscores, all lower case and the plural "s" on the end. Then your model is like this.

class InvFirstMaterial < ActiveRecord::Base
end
drobazko commented 12 years ago

Ok, thanks