-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA224
Hallo Usergroup,
ich habe hier ein merkwürdiges Phänomen, vielleicht könnt ihr da was mit
anfangen, wie das zustande kommt.
Commodity.rb:
class Commodity < ActiveRecord::Base
belongs_to :region
has_many :countries, :through => :region
named_scope :legal_for_country, lambda { |country_code|
{ :include => :countries,
:conditions => [" countries.country_code = ?", country_code] }}
end
Region.rb:
class Region < ActiveRecord::Base
has_many :countries
has_many :commodities
end
Country.rb:
class Country < ActiveRecord::Base
belongs_to :region
end
Allerdings, wenn ich das ganze dann teste, erhalte ich folgendes:
>> Commodity.legal_for_country('DE').all
ActiveRecord::StatementInvalid: PGError: ERROR: column
regions.region_id does not exist
LINE 1: ...EFT OUTER JOIN "regions" ON ("commodities"."id" = "regions"....
^
: SELECT "commodities"."id" AS t0_r0, "commodities"."name" AS t0_r1,
"commodities"."description" AS t0_r2, "commodities"."maincategory" AS
t0_r3, "commodities"."created_at" AS t0_r4, "commodities"."updated_at"
AS t0_r5, "commodities"."user_id" AS t0_r6,
"commodities"."product_file_name" AS t0_r7,
"commodities"."product_content_type" AS t0_r8,
"commodities"."product_file_size" AS t0_r9,
"commodities"."product_updated_at" AS t0_r10, "commodities"."licence_id"
AS t0_r11, "commodities"."preview_id" AS t0_r12,
"commodities"."resolution_id" AS t0_r13, "commodities"."deleted" AS
t0_r14, "commodities"."deleted_at" AS t0_r15, "commodities"."region_id"
AS t0_r16, "countries"."id" AS t1_r0, "countries"."l18n_name" AS t1_r1,
"countries"."created_at" AS t1_r2, "countries"."updated_at" AS t1_r3,
"countries"."country_code" AS t1_r4, "countries"."region_id" AS t1_r5
FROM "commodities" LEFT OUTER JOIN "regions" ON ("commodities"."id" =
"regions"."region_id") LEFT OUTER JOIN "countries" ON
("countries"."region_id" = "regions"."id") WHERE (
countries.country_code = E'DE')
Postresql beschwert sich ja vollkommen zurecht, nur warum wird da das
sql verkehrt zusammen gesetzt?
Vielen Dank an jeden, der sich darüber Gedanken macht,
Daniel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.12 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iFYEARELAAYFAkwbnTIACgkQBCmB9LBcgGCmowDeLaBkUQfDh/99HZY7Q5S+4Am7
oUsFSdRAEXg1YQDeMdJ6oxLuzDBltmVDilrvtw1jGprkDrqFqWQKxw==
=uF/p
-----END PGP SIGNATURE-----
_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/listinfo/rubyonrails-ug