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
hasOne().through() attach and joining issue #162
Comments
bump, anyone? ;) |
That sounds like a bug...
If that works, then go for it... I'm thinking there should be a way of flexibly defining joins/relations outside of the ones provided... which would make creating these types of complex associations easier (related #127) |
That's the point - the |
Oh... actually, what if you do a |
Oh let me try that! |
Yep, that works! Thanks for the idea. Now the other issue then is the prefixing of the ids, but I will open another issue for that. |
@tgriesser can you mark this one as a bug? Even though using |
+1. I'm missing the ability to use hasOne/through. Is there a workaround which lets you still retrieve
? |
The project leadership of Bookshelf recently changed. In an effort to advance the project we close all issues older than one year. If you think this issue needs to be re-evaluated please post a comment on why this is still important and we will re-open it. We also started an open discussion about the future of Bookshelf.js here #1600. Feel free to drop by and give us your opinion. |
Spent some time trying to figure this out, but couldn't figure it out.
I have comments, which are related to different entities through pivot tables with foreign keys, to retain referential integrity.
I could easily get the entity for each comment, by setting up a
belongsToMany
relation. But this returns a collection and I would have to always check the collection length and then select the first element. Of course this is not the end of the world, but it would be nice if it was possible to set up ahasMany
through
relationship.Checking the tests I saw that this type expects a table with an
id
and a foreign key column, but my schema has two foreign key columns, e.g.entity_id
andcomment_id
.I tried to pass in different keys as params to the relation methods but in one way or another it never worked out, as the produced sql always tries to join on
pivottable.id
, which for my purpose should bepivottable.entity_id
.So I tried to set up a
hasOne
relation on theComment
model withthrough
like this:Am I making any sense here? What I basically is a
belongsToMany
relation with a limit of 1, which does not return a collection but a model. So ahasOne
relation, which uses a pivot table with the structure of abelongsToMany
pivot table.Am I missing something obvious?
On a side note: Attaching to a
hasOne
through
relation was inserting into the database correctly using the following sql:After that
Bookshelf
tries to add the model to thecollection
which is amodel
in the case of ahasOne
relation. Because it does not have anadd
method an error is thrown. I suppose I'm hitting an edge case here?!The text was updated successfully, but these errors were encountered: