2011-08-12 65 views
1

我試圖配置Texticle並在遷移時遇到此錯誤。錯誤味精是指我打上< < < <架構不存在Postgresql和Texticle的錯誤

PGError: ERROR: schema "half_links" does not exist 
:  CREATE VIEW searches AS 
    SELECT items.id AS searchable_id, items.name AS term, 
     CAST('Item' AS varchar) AS searchable_type 
    FROM items 
    UNION 
    SELECT half_links.id AS searchable_id, half_links.item.name AS term,  <<<< 
     CAST('HalfLink' AS varchar) AS searchable_type 
    FROM half_links 

行這是我的移民

class CreateSearches < ActiveRecord::Migration 
    def self.up 
    ActiveRecord::Base.connection.execute <<-SQL 
    CREATE VIEW searches AS 
    SELECT items.id AS searchable_id, items.name AS term, 
     CAST('Item' AS varchar) AS searchable_type 
    FROM items 
    UNION 
    SELECT half_links.id AS searchable_id, half_links.item.name AS term, 
     CAST('HalfLink' AS varchar) AS searchable_type 
    FROM half_links 
    SQL 
end 

和模型

:half_link belongs_to :item 
:item has_many :half_links 

林在我的本地PSQL運行此。我怎樣才能解決這個問題?

+1

「half_links.item.name」是什麼意思? –

回答

1

錯誤在第二次選擇。 half_links.item.name使Postgres假設half_links是一個架構名稱(正確的語法是..)

看到你的關聯是如何,我想你的意思是要獲得屬於half_links的項目的名稱。

因爲Postgres對Rails的協會是如何工作的不知道,你需要給自己的數據:

CREATE VIEW searches AS 
    SELECT items.id AS searchable_id, items.name AS term, 
     CAST('Item' AS varchar) AS searchable_type 
    FROM items 
    UNION 
    SELECT half_links.id AS searchable_id, items.name AS term, 
     CAST('HalfLink' AS varchar) AS searchable_type 
    FROM half_links join items on half_links.item_id = items.id 

這是假設在half_linksitems外鍵被稱爲item_id它應該是,如果您使用Rails遷移創建了這些表。

此外,這將只顯示實際上具有與其關聯的項目的半鏈接,如果可能有沒有項目的項目,則將join更改爲outer join。在這些情況下,術語將爲NULL。

+0

你在指甲上擊中它。做得好! – Julien

相關問題