I'm currently trying to use the same struct in many tables and was looking for something like this:
instead of having to make separate structs for each table. Keep up the good work!
Ironically this used to work, but was removed when insertable_into was changed to derive(Insertable_. This has come up enough times that it's worth pursuing (I don't like the idea of giving multiple arguments to table_name, I think this needs a more explicit API.) Happy to do the legwork of implementing if someone proposes an API that seems reasonable.
Since this is not a feature that will require a breaking change, it is on hold until after 1.0.
Thanks for the response.
The first thing I tried was actually multiple table_name statements - maybe this is more intuitive:
I tried that as well before finding this issue. Seems reasonable to me.
I think that API is decent, but it has a few problems. The biggest one is that not all of our derives can handle more than one table (Identifiable semantically can't, AsChangeset can't because of its definition).
I'm fine with not being able to derive Identifiable on a struct that has multiple table names, as that'd be pretty nonsense anyway. Not being able to derive AsChangeset on the same struct is unfortunate though, as these two traits often go together.
Master is currently tracking 2.0, so we can technically make this change if we want (though it'd need a proposal on discourse following the template like all other breaking changes), but the big question is whether it's worth it.
All our derives that look at #[table_name] will need to be updated to handle multiple tables if they can, or error if not. It's probably worth getting a list of all affected derives before making the final call on what to do with AsChangeset, or if we should just go with a different, insertable specific API
Any update on this? :)
I just ran into this issue, when I tried to the pattern that @Zsarl posted above (multiple table_name attributes).
@Boscop We are happy to receive a fully formulated feature request for this, otherwise as always: There is no update on an issue as the issue contains no update. That won't change by asking there, so please do ask such questions.
Most helpful comment
Thanks for the response.
The first thing I tried was actually multiple table_name statements - maybe this is more intuitive:
[derive(Insertable)]
[table_name="table1"]
[table_name="table2"]