Hi all.

I have a situation here:
One of my models (called, basically, Mention) is stored not in one table,
but in "dumbly sharded" list of tables:
* mentions of client 1 in table mentions_client_1
* mentions of client 82 in table mentions_client_82
...and so on.

So, class Mention has method Mention.make_class(client), which dynamically
generates class, descending from Mention, with "right" dataset
:"mentions_client_#{client.id}".

Surprisingly, everything works pretty well.

But there goes complactions:
When I generate class based on Mention, I setup some additional
associations:

one_to_many: :topics,
  class: MentionTopic,
  conditions: {client_id: self.client.id} # should be setup dynamically
because of this condition

And corresponding association in MentionTopic:

many_to_one :mention,
    dataset: ->{Mention2.make_class(client).dataset.where(id: mention_id)}

End everything still works, hooray!

Now the problem:

MentionTopic.where(client_id: 1).eager(:mention)
is NOT working: Invalid association topics for Mention
It seems, here the associated class name is deduced from assocation name,
not from association dataset model (and Mention indeed have no associations
:topics, only its descendants have).

How can I fix everything up (without eager everything works fine, but too
slow, unfortunately)?
How can I possibly simplify the entire structure? (Sadly, database schema
redesign is not an option).

Thanks!

V.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to