Thanks a lot Chris. Sadly, I've got my work cut out for me, as changing
the name of the model in this fairly mature application is going to be
some work. But at least it all makes some sense now.
Is it possible to change the model name without changing the name of the
_associations_ that point to it in other models? Or, I guess, to alias
the association name 'request' to an 'actual' association named
service_request or whatever. To give me less code that has to be
changed? Any advice as to the lowest impact way to change a model name
in a mature application with lots of code that refers to that model, and
to associations in other models that point to that model?
Odd that I got away with it in Rails 1.x, but oh well, I guess it was
really incorrect all along.
Hmm, just changing the model name from Request to AppRequest doesn't
seem to have done it.
I tried to leave the (many) associations pointing to AppRequest (nee
Request) the same, but specify a :class_name and :foreign_key.
It sounds like maybe "request" as the name of an assocation, even when
not the name of the model, is a no-no too?
Man, that lengthy lengthy list of reserved words, which wasn't really
official documentation anyway and seems to be have been discovered only
by experimentation... is leading to one of those times I'm less happy
with ruby/rails.
I've got a lot of refactoring to do. Changing the many association names
to this model every time they are used is not going to be fun.
Hmm, just changing the model name from Request to AppRequest doesn't
seem to have done it.
I tried to leave the (many) associations pointing to AppRequest (nee
Request) the same, but specify a :class_name and :foreign_key.
It sounds like maybe "request" as the name of an assocation, even when
not the name of the model, is a no-no too?
I'm not convinced that has anything to do with this at all. If you
could post your teeny tiny example I might be able to work out what is
going in (given that I wrote the code behind include in 2.1.2)
Yeah, you're right, sorry, thanks so much for your help. Probably for
the best that i changed the model name from Request anyway, might as
well commit that to my svn since it's advertised as a Rails reserved
word.
I just posted this to the forum with a different subject, since it ended
up having nothing to do with this, but. But I was forced to really get
down and dirty with my testing, and it turns out it's because I had
over-ridden and = on one of the models involved. I got away with
that in Rails 1 (perhaps AR didn't used to use these methods?), but not
in Rails 2. Okay, more refactoring, this one's even more of a pain then
the last one. Oh well, I guess I was being too clever before.
Yeah, you're right, sorry, thanks so much for your help. Probably for
the best that i changed the model name from Request anyway, might as
well commit that to my svn since it's advertised as a Rails reserved
word.
I just posted this to the forum with a different subject, since it
ended
up having nothing to do with this, but. But I was forced to really get
down and dirty with my testing, and it turns out it's because I had
over-ridden and = on one of the models involved. I got away with
that in Rails 1 (perhaps AR didn't used to use these methods?), but
not
in Rails 2. Okay, more refactoring, this one's even more of a pain
then
the last one. Oh well, I guess I was being too clever before.
Rails has always provided and = for getting/setting
attributes. :include was largely rewritten in 2.1 and does indeed use
to read attributess, the corresponding bits of 2.0 or 1.2 obviously
didn't
The odd thing is that I get away with over-riding and = until I try
defining an association with a pre-fetch :include that involves the
model with the over-ridden and =. And googling around, I can see
several people suggesting over-ridding and = on an AR model to
accomplish various clever things. So maybe it is a bug? Regardless, I
think I'll try to refactor to do not do that to avoid the risk of
getting in the way of AR. It seems to be rather easier than one would
like to get in the way of AR.
In particular, the too-clever thing I was doing was having an AR that
could take arbitrary keys and either store them in an attribute, if it
exists, or in a serialized hash, if otherwise. An excerpt of the
relevant stuff: