Hey Jeremy,

I am seeing some strange behavior with many_to_many associations, 
association cloning, and classes.

I am building a set of sequel models to interact with a legacy database 
that we are slowly migrating away from, and trying to untangle some 
polymorphism in the old database.

I started with a bunch of associations like the following:

many_to_many :audios, class: 'Legacy::Models::SequelAudio', join_table: 
:content_syndications, left_key: :contentable_id, right_key: :content_id do 
|ds|
   ds.where(:contents[:type] => 'Contents::Audio')
end

I then realized that I can do the following, in order to get rid of the 
block on the association:

class Legacy::Models::SequelAudio < Legacy::Models::SequelContent
  set_dataset LEGACY_DB[:contents].where(type: 'Contents::Audio')
end

Which leads to:

many_to_many :audios, class: 'Legacy::Models::SequelAudio', join_table: 
:content_syndications, left_key: :contentable_id, right_key: :content_id

At this point, I realize I am relying on something cool going on with the 
class argument.

I then try to further DRY up my code by doing this:

many_to_many :audios, clone: :contents, class: 'Legacy::Models::SequelAudio'

Unfortunately, it seems like the class that I am specifying is no longer 
getting applied. The association returns records with the class that is on 
the cloned contents association, not the audios association. And it isn't 
using the correct dataset anymore.

Is there something else that I need to be doing? Am I misunderstanding 
cloning?

-Ben

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/0d070dc1-abe1-4849-b979-25afef58a539n%40googlegroups.com.

Reply via email to