Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are relations supposed to work with inheritance? #49

Open
thokari opened this issue Nov 25, 2014 · 1 comment
Open

Are relations supposed to work with inheritance? #49

thokari opened this issue Nov 25, 2014 · 1 comment

Comments

@thokari
Copy link

thokari commented Nov 25, 2014

Hi again,

say I have a model that extends another model, like StaffUser and User for example.
Now when I set it up like the examples suggest, but also have StaffUser extends User, then, besides still having the problem, that the foreign keys for the relationships do not get set properly (#48), my 'Address' instance (when assigning a 'StaffUser' instance to its 'user' property) now has two fields, user_id and staff_user_id (both 'null' as of issue mentioned before).

I realise this is a complex issue, and coming from an object oriented background I might be expecting too much.
However your software looks very promising, and even without this feature it would save a lot of boilerplate code.

Thanks for your help!
Thomas

@kmalakoff
Copy link
Member

Hi Thomas,

I believe we have only been testing the mapping of one model to one table up until now.

Let's leave this issue open and we will write tests for this scenario and try to get them working consistently across database variants.

For now, you should be able to manually merge the schema using something like (I haven't tested this code):

_ = require 'underscore'

class User extends (require 'backbone').Model
  schema: 
    field_1: []

class StaffUser extends User
  schema: _.extend {
    field_2: []
  }, (new User).schema().raw
  sync: (require 'backbone-mongo').sync(StaffUser)

We'll let you know when we've made this a little simpler....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants