vapor / fluent-kit

Swift ORM (queries, models, and relations) for NoSQL and SQL databases
MIT License
217 stars 116 forks source link

owner likely unsaved, attach within attach closure #586

Closed wibed closed 1 year ago

wibed commented 1 year ago

related to recent pr: https://github.com/vapor/fluent-kit/pull/585

mentionable:

code:

    try await event.$account.attach(Account, on: database, { roster in
      try await roster.$promise.attach(Promise, on: database) })
[Vapor] siblings relation Siblings<Roster, Promise, RosterPromise>
(from: [roster_id], to: [promise_id]) is missing owning model's ID (owner likely unsaved)
gwynne commented 1 year ago

Right - the roster model hasn't been saved yet while you're still editing it, so you can't use the attach methods on it unless you manually allocate an ID for it and assign that ID to the model before returning from the closure.

wibed commented 1 year ago

thanks for the clarification!