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
attach
with additional attributes
#29
Comments
At the moment I'm just creating a join table model like so:
|
So I think I intended to be able to pass a model as a Right now you can do this: collection.belongsToMany(db.Models.Link).attach(link.attributes) And the object that is set as the attributes will be saved with additional columns, but I realize that doesn't help with wanting a model/methods/timestamps on the join table... I'll think a bit more about this one. |
Oh... I know what I was going to do here - the equivalent of ActiveRecord's links: function() {
return this.hasMany(Links, CollectionsLinks);
} And then you'd have a |
Yep that makes sense. |
So @vjpr - this is sort of in the works. With 0.3.0 I added |
Hey, just wondering if there's an update on how to attach relations with a join model/table with additional attributes (timestamps, etc)? |
I ended up here with the same question after searching 😉, I then found the following hints, which I thought it would be helpful to post here:
|
Hi @ErisDS. Thanks for pointing this out. I'll try to update the docs soon. |
When I call
attach
I generally want to be able to set other attributes on the M2M relation.A common example might be a timestamp.
Something like
collection.belongsToMany(db.Models.Link).attach(link, {archived: false})
I'd also like to be able to set defaults and methods for the M2M relation.
I found the following which seems to indicate you can't pass in a model and additional params - I'd have to create a hash myself.
Also the comments for
belongsToMany
say:I expected to be able to pass a
Bookshelf.Model
, whosedefaults
would be set on attach, as well as timestamps, etc.Examples of using many to many relations with additional attrs on the join table would be helpful.
The text was updated successfully, but these errors were encountered: