-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Docs: How to link new object to existing objects? (many-to-many relationship) #359
Comments
Without setting the To fix this, you should set the Insert of |
FWIW, here's a working service that allows you to add tags to "teams". This may be helpful because it's another example of a many-to-many. Notice how in this example we also use the This piece is what's probably most important here. data.tags.extend(
[
await m.Tag.as_unique_async(self.repository.session, name=tag_text, slug=slugify(tag_text))
for tag_text in tags_added
],
) This will force a lookup to match for existing tags before inserting a new tag record. |
Thank you for the response!
Hm I'm not sure I understand, sorry; the Job (aka Post) is new and so doesn't need to be matched, just needs to be created. The things that needs to be matched is the Variants (aka Tags) that it is referencing. To form that constraint, (1) would I still add match_fields in the
So this works but I'm quite confused by this behavior :( I added the UniqueMixin, but that alone doesn't do anything, I have to use
However, doesn't Also, I had a Thanks again for your patience |
Ah, ok i think in general, I figured this out. There is something happening in my earlier validation step when I load the Variants causing the Variant to be treated as modified (using I would still find it helpful to have more documentation and guidance in docs around:
|
Summary
I've tried to understand and execute the Post-Tag example for my own use case with a many-to-many relationship, and I am not able to get working how to add a new Post, say, that uses existing tags.
In my code, I do:
and I get:
But I'm only trying to create a new Job, I'm not intending to create new variants. How do I just link the new job to the existing variants / the new post to the existing tags?
The text was updated successfully, but these errors were encountered: