Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Raise error when trying to eager load a polymorphic belongs to

  • Loading branch information...
commit 2b0d1113b327b6a707deab4e3eddf16f10475185 1 parent 27b7fac
@durran durran authored
View
2  lib/config/locales/bg.yml
@@ -10,7 +10,7 @@ bg:
Не е намерен документ %{klass} с id(та) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Базата данни трябва да е от тип Mnogo:DB, а не %{name}.
invalid_type:
View
2  lib/config/locales/de.yml
@@ -10,7 +10,7 @@ de:
Dokument für Klasse %{klass} mit ID(s) %{identifiers} nicht gefunden.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Datenbank sollte eine Mongo::DB sein, nicht %{name}.
invalid_type:
View
2  lib/config/locales/en-GB.yml
@@ -10,7 +10,7 @@ en-GB:
Document not found for class %{klass} with id(s) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
"Database should be a Mongo::DB, not %{name}."
invalid_options:
View
2  lib/config/locales/en.yml
@@ -10,7 +10,7 @@ en:
Document not found for class %{klass} with id(s) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
"Database should be a Mongo::DB, not %{name}."
invalid_options:
View
2  lib/config/locales/es.yml
@@ -8,7 +8,7 @@ es:
No se encontró ningún documento para la clase %{klass} con los id(s) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
La base de datos debería ser una instancia de Mongo::DB, en lugar de %{name}.
invalid_type:
View
2  lib/config/locales/fr.yml
@@ -10,7 +10,7 @@ fr:
Document introuvable pour la classe %{klass} avec les ids %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
La base de données doit être une Mongo::DB, pas %{name}.
invalid_type:
View
2  lib/config/locales/hi.yml
@@ -10,7 +10,7 @@ en:
"%{identifiers} id(s) के साथ, वर्ग %{klass} के लिए दस्तावेज़ नहीं मिला."
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
"डेटाबेस Mongo::DB होना चाहिए, %{name} नहीं."
invalid_options:
View
2  lib/config/locales/hu.yml
@@ -10,7 +10,7 @@ hu:
"%{klass} osztályban, %{identifiers} id(k)-el nem található dokumentum."
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Az adatbázisnak Mongo::DB-nek kellene lennie, nem %{name}.
invalid_type:
View
2  lib/config/locales/id.yml
@@ -10,7 +10,7 @@ id:
Dokumen tidak ditemukan untuk kelas %{klass} dengan id %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Database harus Mongo::DB, bukan %{name}.
invalid_type:
View
2  lib/config/locales/it.yml
@@ -10,7 +10,7 @@ it:
Documento non trovato per la classe %{klass} con id(s) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Il database dovrebbe essere un Mongo::DB, non %{name}.
invalid_type:
View
2  lib/config/locales/ja.yml
@@ -10,7 +10,7 @@ ja:
次のDocumentは見つかりませんでした。class %{klass} with id(s) %{identifiers}
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
次のDatabaseは利用できませんでした。%{name}
invalid_type:
View
2  lib/config/locales/kr.yml
@@ -10,7 +10,7 @@ kr:
클라스 %{klass}와 id를 %{identifiers} 위한 문서를 찾을수 없습니다.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
데이타베이스가 Mongo::DB이어야 합니다, %{name}이면 안됩니다.
invalid_type:
View
2  lib/config/locales/nl.yml
@@ -10,7 +10,7 @@ nl:
Document niet gevonden voor class %{klass} met de id(s) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Database moet een Mongo::DB zijn, niet een %{name}.
invalid_type:
View
2  lib/config/locales/pl.yml
@@ -10,7 +10,7 @@ pl:
Nie znaleziono dokumentu dla klasy %{klass} o id %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Baza danych powinna być typu Mongo::DB, a nie %{name}.
invalid_type:
View
2  lib/config/locales/pt-BR.yml
@@ -10,7 +10,7 @@ pt-BR:
Nenhum documento encontrado para a classe %{klass} com os id(s) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
A base de dados deverá ser uma Mongo::DB, em vez de %{name}.
invalid_type:
View
2  lib/config/locales/pt.yml
@@ -10,7 +10,7 @@ pt:
Nenhum documento encontrado para a classe %{klass} com os id(s) %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
A base de dados deverá ser uma Mongo::DB, em vez de %{name}.
invalid_type:
View
2  lib/config/locales/ro.yml
@@ -10,7 +10,7 @@ ro:
Nu există document în clasa %{klass} cu id %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Baza de date ar trebui să fie de tipul Mongo::DB, nu %{name}.
invalid_type:
View
2  lib/config/locales/ru.yml
@@ -10,7 +10,7 @@ ru:
Документ класса %{klass} с id %{identifiers} не найден.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
База данных должна быть Mongo::DB, а не %{name}.
invalid_type:
View
2  lib/config/locales/sv.yml
@@ -10,7 +10,7 @@ sv:
Inget dokument kunde hittas för klass %{klass} med id %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Databasen bör vara Mongo::DB, inte %{name}.
invalid_type:
View
2  lib/config/locales/vi.yml
@@ -10,7 +10,7 @@ vi:
Không tìm thấy văn bản cho lớp %{klass} với định danh %{identifiers}.
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
Cơ sở dữ liệu nên là Mongo::DB, không phải %{name}.
invalid_type:
View
2  lib/config/locales/zh-CN.yml
@@ -12,7 +12,7 @@ zh-CN:
没有发现类是%{klass}id(s)是%{identifiers}的文档
eager_load:
"Eager loading :%{name} is not supported due to it being a many-to-many
- relation."
+ or polymorphic belongs_to relation."
invalid_database:
数据库应该是Mongo::DB,而不是%{name}.
invalid_type:
View
1  lib/mongoid/relations/referenced/in.rb
@@ -122,6 +122,7 @@ def criteria(metadata, object, type = nil)
#
# @since 2.2.0
def eager_load(metadata, criteria)
+ raise Errors::EagerLoad.new(metadata.name) if metadata.polymorphic?
klass, foreign_key = metadata.klass, metadata.foreign_key
klass.any_in("_id" => criteria.load_ids(foreign_key).uniq).each do |doc|
IdentityMap.set(doc)
View
48 spec/functional/mongoid/relations/referenced/in_spec.rb
@@ -616,28 +616,44 @@
Mongoid.identity_map_enabled = false
end
- let!(:person) do
- Person.create(:ssn => "243-12-5243")
- end
+ context "when the relation is not polymorphic" do
- let!(:post) do
- person.posts.create(:title => "testing")
- end
+ let!(:person) do
+ Person.create(:ssn => "243-12-5243")
+ end
- let(:metadata) do
- Post.relations["person"]
- end
+ let!(:post) do
+ person.posts.create(:title => "testing")
+ end
- let(:eager) do
- described_class.eager_load(metadata, Post.all)
- end
+ let(:metadata) do
+ Post.relations["person"]
+ end
- let!(:map) do
- Mongoid::IdentityMap.get(Person, person.id)
+ let(:eager) do
+ described_class.eager_load(metadata, Post.all)
+ end
+
+ let!(:map) do
+ Mongoid::IdentityMap.get(Person, person.id)
+ end
+
+ it "puts the document in the identity map" do
+ map.should eq(person)
+ end
end
- it "puts the document in the identity map" do
- map.should eq(person)
+ context "when the relation is polymorphic" do
+
+ let(:metadata) do
+ Rating.relations["ratable"]
+ end
+
+ it "raises an error" do
+ expect {
+ described_class.eager_load(metadata, Rating.all)
+ }.to raise_error(Mongoid::Errors::EagerLoad)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.