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

Handle multiple relationships between two same objects #574

Open
gjuchault opened this issue Sep 28, 2016 · 2 comments
Open

Handle multiple relationships between two same objects #574

gjuchault opened this issue Sep 28, 2016 · 2 comments
Labels

Comments

@gjuchault
Copy link

Bug report

Hi,

Here is a simplified script of what is notworking

var A = thinky.createModel('A', {id: String});
var B = thinky.createModel('B', {id: String});

A.hasAndBelongsToMany(B, 'bs', 'id', 'id');
B.hasAndBelongsToMany(A, 'as', 'id', 'id');

var a = new A({id: 'a1'});
var b = new B({id: 'b1'});

a.addRelation('bs', b);
a.addRelation('bs', b);
a.addRelation('bs', b);

This is not working. The weird thing is that if I make three objects on my own with A_id and B_id it will work (r.table('A_B').insert([ rel, rel, rel ]);) then think knows about it

@neumino
Copy link
Owner

neumino commented Sep 30, 2016

The short answer is that you cannot add multiple times the same relations, at least that's how hasAndBelongsToMany was built.

What's your use case behind multiple relations? Maybe extra data in the relation would be what you need? Though it's not implemented at the moment...

@gjuchault
Copy link
Author

Example case:

  • A Promotion Table
  • A Item table

1 beer - $7
3 beer - $18

Promotion n:m Item

Promotion called "3 beer" has 3 times the Item called "Beer".

I tried once adding extra data to relationship. #282 is mine :D. I'll check this if I have time one day o/.

But why would hasAndBelongsToMany supports only one relationship ? (When it supports "without coding effort" if there is three times the same relationship inside ?

The easy way would be to change addRelation to make an entry inside the table with id1_id2 without caring if there is already an entry and then everything would work

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

No branches or pull requests

2 participants