The two schemes cannot be compared, since they have different relationships, you must look at the specifications for the tables, and then determine which one is suitable for the necessary relations.
The first means that the User can only be a member of one company (relation to_to). While the second scheme implies that the User can be a member of many companies (the has_many relationship)
If you are looking for a scheme that can (or will be later) supporting has_many relationships, then you want to go with the second. For this reason, compare:
// select all users in company x with schema 1
select username, companyname from companies
inner join users on users.companyid = companies.companyid
where companies.companyid = __some_id__;
and
// select all users in company x with schema 2
select username, companyname from companies
inner join usercompanies on usercompanies.companyid = companies.companyid
inner join users on usercompanies.userid = users.userid
where companies.companyid = __some_id__;
You have an additional join in the selection table. If you only need the belongs_to relation, then the second query does more work than it should, and therefore makes it less efficient.
source share