Open
Description
We need to implement a many-to-many relationship between the existing User model and a new model, Group, with additional fields on the relationship to store extra data. This will involve creating a join table (intermediate model) that will store the relationship between the two models, along with 2 additional fields: role, role of the user on the group and joined_at, the date when the user joined the group.
The relationship should be implemented as follows:
- The User model should have a many-to-many field to Group via the intermediate model.
- The intermediate model should store the role and joined_at fields.
- The intermediate model should include foreign keys to both User and Group, along with any extra fields necessary for the relationship.
- The join table should be created via a migration, and the schema should be updated to reflect this new relationship.
Write tests to ensure that:
- The many-to-many relationship between User model and Group model works correctly.
- The additional fields on the join table are properly set and accessible.
- Existing functionality and data in User model and Group model are unaffected by the new relationship.
- There should be no impact on existing tests. If you are adding a test to an existing file, please do so at the end of the file.