You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is regarding a small issue I observed in postgresql adapter for rails. I am using postgre 9.0 as database with rails 2.3.8 and pg adapter 0.9.0 x86-mswin32.
I have roles and users models in my application and they both are associated with each other through a bridge table roles_users.
In roles_user.rb I have specified composite primary key as "set_primary_keys :user_id, :role_id" ( I am using composite_primary_keys (2.3.2) gem )
Now when I call "self.roles.push(Role.find(:first, :conditions => {:name => 'user'}))" it gives me following error
Column "user_id,role_id" does not exist.
INSERT INTO "roles_users" ("updated_at", "created_at", "user_id", "role_id") VALUES (NULL, NULL, 16, 5) RETURNING "user_id,role_id"
After looking into it I found that the error is because of following method of postgrsql_adapter.rb
#!ruby
def quote_column_name(name) #:nodoc:
PGconn.quote_ident(name.to_s)
end
On executing the roles.push query this method is being passed following input by insert method in the same file
Input: [:user_id, :role_id]
The method calls quote_indent and generates following output which causes PG Error mentioned above.
Output: ""user_id,role_id""
To solve this I have changed the method as given below and it worked fine.
#!ruby
def quote_column_name(name) #:nodoc:
if name.is_a(Array)
quoted_columns = []
for column_name in name
quoted_columns << PGconn.quote_ident(column_name.to_s)
end
quoted_columns.join(',')
else
PGconn.quote_ident(name.to_s)
end
end
With this new code the output generated for the same input is ""user_id","role_id""
I am not sure whether its a bug in the postgresql_adapter.rb file or I am doing some silly mistake.
The text was updated successfully, but these errors were encountered:
Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).
The PostgreSQL adapter for ActiveRecord isn't part of this library, it's part of ActiveRecord. I suggest you search for the issue in [[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails|their bugtracker]], and if it hasn't been mentioned yet, submit it there. Thanks!
Original report by crazycrv (Bitbucket: crazycrv, ).
This is regarding a small issue I observed in postgresql adapter for rails. I am using postgre 9.0 as database with rails 2.3.8 and pg adapter 0.9.0 x86-mswin32.
I have roles and users models in my application and they both are associated with each other through a bridge table roles_users.
In roles_user.rb I have specified composite primary key as "set_primary_keys :user_id, :role_id" ( I am using composite_primary_keys (2.3.2) gem )
Now when I call "self.roles.push(Role.find(:first, :conditions => {:name => 'user'}))" it gives me following error
Column "user_id,role_id" does not exist.
INSERT INTO "roles_users" ("updated_at", "created_at", "user_id", "role_id") VALUES (NULL, NULL, 16, 5) RETURNING "user_id,role_id"
After looking into it I found that the error is because of following method of postgrsql_adapter.rb
On executing the roles.push query this method is being passed following input by insert method in the same file
Input: [:user_id, :role_id]
The method calls quote_indent and generates following output which causes PG Error mentioned above.
Output: ""user_id,role_id""
To solve this I have changed the method as given below and it worked fine.
With this new code the output generated for the same input is ""user_id","role_id""
I am not sure whether its a bug in the postgresql_adapter.rb file or I am doing some silly mistake.
The text was updated successfully, but these errors were encountered: