Skip to content

How to collect resulting ids from an Model::insert_many() #2191

Answered by tyt2y3
V-FEXrt asked this question in Q&A
Discussion options

You must be logged in to vote

Released! https://github.com/SeaQL/sea-orm/releases/tag/1.1.6

assert_eq!(
    cakes_bakers::Entity::insert_many([
        cakes_bakers::ActiveModel {
            cake_id: Set(1),
            baker_id: Set(2),
        },
        cakes_bakers::ActiveModel {
            cake_id: Set(2),
            baker_id: Set(1),
        },
    ])
    .exec_with_returning_keys(db)
    .await
    .unwrap(),
    [(1, 2), (2, 1)]
);

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@V-FEXrt
Comment options

Comment options

You must be logged in to vote
3 replies
@V-FEXrt
Comment options

@tyt2y3
Comment options

@krateng
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by tyt2y3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants