-
Notifications
You must be signed in to change notification settings - Fork 38
has many through #114
Comments
Hi @nibarulabs You'll need to define the target relation. e.g.: btw:
|
Hi @PhilWaldmann, thanks for your reply. Hmm, still getting the same error. I actually played with adding I've noticed something else too that might be fine, but wanted to double check. I added some console log to print out the role after I look it up and I noticed it adds the has many attributes to the class even though I'm using the
I have all my models introspecting the data structure from the table and my postgres table definition for roles looks pretty standard:
There are no I'm not trying to confuse the issue, but I suspect that having those attributes there and the relations object is empty - maybe there's some issue there? Feels like I'm close and I'm just missing something small.. I'm going to go through your test code to see how you're testing things for |
Ok, I found a workaround. In my user.js I added the following function:
This now allows me to do something like:
I get that it's not ideal and not really 'correct', but it gets the association working for me, albeit with more db hits (I don't need to over optimize at this point and can fix later). If there are any suggestions as to what else I can try to get the |
Yeah, that's not the prettiest solution. |
I have the 'old user and roles issue. I've done this numerous time in Rails and other frameworks, so it should be well understood.
Each model has the Store import for postgres at the top of the file:
When I load the User and query for it and include
roles
I can get the expected role back. But when I create a new user and then add a role via:I get this error:
I'm at a loss at this point. I've tried different combinations of options on all 3 models with no luck. I'd prefer to use HMT but I'm starting to try to rework this to get it to work. Downside of that though is that I will have other HMT relations and if I can't get this one to work, then the others won't either.
Maybe I'm missing something simple? Thanks.
The text was updated successfully, but these errors were encountered: