Ruby on Rails
Monday, May 4, 2015
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/98873798-5519-4aca-842f-9247b7aced7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
Hi,
I have a problem with dynamic table_name with 4.2.1. With 2.1.9, it was working well
here my simplify models :
class Aaaa < ActiveRecord::Base
has_one :bbbb, dependent: :destroy, :inverse_of => :aaaa
end
class Bbbb < ActiveRecord::Base
belongs_to :aaaa, :inverse_of => :bbbb
end
Bbbb.table_name = "cccccs"
aa = Aaaa.where(:id => 1)[0]
aa.bbbb
it runs a select query such as : SELECT "cccccs".* FROM "cccccs" WHERE "cccccs"."aaaa_id" = $1 LIMIT 1 [["aaaa_id", 1]]
but if then I do
aa = Aaaa.where(:id => 2)[0]
Bbbb.table_name = "dddds"
aa.bbbb
it runs a select query still on table "cccccs" whereas it should be on "dddds" : SELECT "cccccs".* FROM "cccccs" WHERE "cccccs"."aaaa_id" = $1 LIMIT 1 [["aaaa_id", 1]]
but if I display Bbbb.table_name , it prints "dddds"
when I do
Bbbb.table_name = "cccccs"
aa = Aaaa.where(:id => 1)[0]
aa.bbbb
it runs a select query such as : SELECT "cccccs".* FROM "cccccs" WHERE "cccccs"."aaaa_id" = $1 LIMIT 1 [["aaaa_id", 1]]
but if then I do
Bbbb.table_name = "dddds"
aa = Aaaa.where(:id => 2)[0]
aa.bbbb
it runs a select query on good table such as : SELECT "dddds".* FROM "dddds" WHERE "dddds"."aaaa_id" = $1 LIMIT 1 [["aaaa_id", 2]]
once again, with rails 4.1.9, it was working fine.
It seems that with 4.2.1, table for relation are instanciate when the object is create. Is there a reason for that ? Is there a way to avoid that.
No offence, but please no answer as "you shouldnt do this, doing this is not good, or whatever" , I cant also modify my database. I have to do like this, no choice, and for more than 2 years it was working well ;-)
Im aware that it might not supported, even if I dont understand why. Could it be at least possible to know if there is a reason that now the relation is instantiate when the object is created ? I thought one of the good point of rails was to instantiate things only when you need them.
Are polymorphism or STI not supported anymore ? If they are still, why to force us to had a field on database when table_name can depend on domain name for instance.