How to set PostgreSQL table names in Rails with schema information?

I need to connect my rails application in an old Postgre database. It uses schemas, so in SQL it usually uses something like

SELECT * FROM "Financial".budget

I want to write a budget model, but I do not know how to set the table name in this case. I tried the following:

  • set_table_name 'budget'
  • set_table_name '' Financial .budget '

There is no working group.

+3
source share
7 answers

Now this error is apparently resolved in a 2-3-stable. Take a look at this post.

+3
source
ActiveRecord::Base.establish_connection(
    :schema_search_path => 'Financial,public'
)

If you use Postgres, this is probably "good enough" for most situations.

+4
source

Oracle. ActiveRecord SQL ,

set_table_name "Financial.budget"

SQL

SELECT * FROM "Financial.budget"

.

, Apache Apache. environment.rb :

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
  # abstract_adapter calls quote_column_name from quote_table_name, so prevent that
  def quote_table_name(name)
    name
  end
end

set_table_name "Financial.budget"

SQL

SELECT * FROM Financial.budget
+3

- SQL Rails ?

0
set_table_name "Financial.budget"
0

, ?

SET SEARCH_PATH TO "Financial", public;

:

SELECT * FROM budget;
0

Source: https://habr.com/ru/post/1698885/


All Articles