jwood / tenacity

A database client independent way of managing relationships between models backed by different databases.
MIT License
118 stars 17 forks source link

Add support for Single Table Inheritance #32

Open mattiassvedhem opened 12 years ago

mattiassvedhem commented 12 years ago

I have set up a User model and a Manager model with Single Table inheritance like this :

class User < ActiveRecord::Base
  include Tenacity

  t_has_many :posts, :foreign_key => "user_id"
end
class Manager < User
end

And a Mongoid model :

class Post
  include Mongoid::Document
  include Tenacity

  field :name

  t_belongs_to :user
end

However the association only works when the user is a User and not a Manager. If i try to add posts to a manager I just get an empty array when trying to fetch them trough user.posts.

Any thoughts on this? Thanks

jwood commented 12 years ago

Tenacity currently does not support Single Table Inheritance. I'm not sure what it would take to implement, but I can take a look later on this week after I return from vacation. However, implementing many-to-many will be the next feature I plan on adding. So, it may be a while until I get to this.

Feel free to give it a shot if you'd like.

mattiassvedhem commented 12 years ago

Ok, after some testing.

It does seem to work if I add the user_id manually. However if I change the type of the user, user_id on associated documents gets nil'ed.

I'll see if I can fix it.