Adding Properties to a PersistenceJS relational table

78 views
Skip to first unread message

bamerza

unread,
Jul 30, 2013, 3:11:32 AM7/30/13
to persis...@googlegroups.com

Is there a way to add properties to the relational entities which are created with hasMany?

e.g : I have tables - User & Car:

var User = persistence.define('User', {     
    Name: 'TEXT'        
});

var Car = persistence.define('Car', {       
    Name: 'TEXT'        
});

And then create the many-to-many relational table:

Car.hasMany('users', User, 'cars');
User.hasMany('cars', Car, 'users');

So, the question is - how do I add a property to the relational table created by Persistence?

hasMany does not return anything.

I'd like to add a date property to know when I created the car-user association. If not possible via Persistence, how is this accomplished w/ it ?

Zef Hemel

unread,
Jul 30, 2013, 4:04:20 AM7/30/13
to persis...@googlegroups.com
This is not possible unless you model the relationship as an entity itself.

var CarUser = persistence.define('CarUser', {
  date: "DATE"
});
CarUser.hasOne('car', Car);
CarUser.hasOne('user', User);

-- Zef


--
You received this message because you are subscribed to the Google Groups "persistence.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to persistencej...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages