[OT] Idea to get all columns from multiple tables in DB
doob at me.com
Wed Jan 8 07:19:07 UTC 2020
On 2020-01-07 22:01, Steven Schveighoffer wrote:
> I have a database serialization package that I use to fetch data from a
> database. The column names are all identified or tagged appropriately,
> so I just use:
> connection.query("SELECT * FROM user").byItem!User;
> and it serializes the data from the resulting rows into the struct User
> type for consumption as a range.
> However, if there's a join, it poses a problem. Let's say I have an
> Equipment item, which is owned by a user. I can select both the
> equipment and the owner via:
> SELECT * FROM equipment left join user on (user.id = equipment.owner_id)
> However, this causes problems because I get duplicate columns (e.g. name
> might be in both, or id). Which one goes with which?
IIRC Rails is using the fully qualified column name for everything.
Instead of using "*" it enumerates all columns of, in your case, User.
It will inspect User to figure out all the column names. You can easily
do the same thing in D by inspecting the fields on User.
More information about the Digitalmars-d