List Info

Thread: reflections in dynamically created ActiveRecord models




reflections in dynamically created ActiveRecord models
user name
2006-10-03 22:23:50
Hello,

I have a question regarding some ActiveRecord based models
that I
dynamically create in my app.

For my file based models, when I look at the reflections
hash,
everything looks good.
eg.) SomeModel.reflections produces all of the reflections
associated
with the model.

Now with my non-file based models (ones created dynamically
in
memory), the reflections hash is empty.  Methods for
associations are
created correctly though.
eg.) DynamicModel.reflections produces {}

What would be going on behind the scenes that I'm may not be
fully
aware of that would be cuasing this issue?  My thoughts are
leading me
to think it's some sort of cacheing issue, but I'm not 100%
sure.

Thanks in advance,
Andrew

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-coregooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---

reflections in dynamically created ActiveRecord models
user name
2006-10-04 05:46:59
Ok, some further research has ruled out the caching theory.

If I do something like this...

body = lambda do
            set_table_name class_name
            belongs_to :user
            belongs_to :another_association
          end

Object.const_set class_id, Class.new(ActiveRecord::Base,
&body)
p class_id.to_s.constantize.reflections

produces reflections as {} already!

The dynamic class works fine for accessing the associations
like
obj.user and such, but because the reflections hash is empty
I can't
use things like :include => :user with it.

Any core members or hard core rail-ites with any idea as to
what I'm
doing wrong?

Thanks,
Andrew

On 10/3/06, Andrew Kaspick <akaspickgmail.com> wrote:
> Hello,
>
> I have a question regarding some ActiveRecord based
models that I
> dynamically create in my app.
>
> For my file based models, when I look at the
reflections hash,
> everything looks good.
> eg.) SomeModel.reflections produces all of the
reflections associated
> with the model.
>
> Now with my non-file based models (ones created
dynamically in
> memory), the reflections hash is empty.  Methods for
associations are
> created correctly though.
> eg.) DynamicModel.reflections produces {}
>
> What would be going on behind the scenes that I'm may
not be fully
> aware of that would be cuasing this issue?  My thoughts
are leading me
> to think it's some sort of cacheing issue, but I'm not
100% sure.
>
> Thanks in advance,
> Andrew
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-coregooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )