0

Articleモデルがあり、ロケールに関係なくすべてのエントリを取得したいと思います。

Article.allは、翻訳(article_translationsテーブルのtranslatableフィールド)を含まない元のオブジェクト(articlesテーブルに格納されているオブジェクト)のみを返します。また、現在のI18n.localeとは異なるロケールのオブジェクトでは、フィールドがnil(?)に設定されています。

Article :: Translation.allは、言語に関係なくすべてのオブジェクトを返しますが、翻訳クラス(article_translationsテーブル-翻訳可能として設定されているフィールドのみを意味します)からのみ返します。

Rails3.0.7とGlobalize30.1.0BETAを使用しています。

これはモデルです:

class Article < ActiveRecord::Base
  translates :title, :content, :slug, :published_at, :created_at, :updated_at
end

これは移行ファイルです:

class CreateArticles < ActiveRecord::Migration
  def self.up
    create_table :articles do |t|
      t.string :title
      t.text :content
      t.string :slug
      t.boolean :published
      t.datetime :published_at

      t.timestamps
    end

    add_index :articles, :slug
    Article.create_translation_table! :title => :string,
                                      :content => :text,
                                      :slug => :string,
                                      :published_at => :datetime,
                                      :created_at => :datetime,
                                      :updated_at => :datetime
  end

  def self.down
    Article.drop_translation_table!
    drop_table :articles
  end
end
4

1 に答える 1

1

両方のテーブルで:title、:content、:slugが複製されています。モデル定義では、これらは変換テーブルにのみ存在する必要があります。:-)

于 2011-10-17T20:44:15.337 に答える