Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Data Relationships with SQL and Sequelize Retrieve Related Data in Sequelize Queries Next Steps

Sai Perez
seal-mask
.a{fill-rule:evenodd;}techdegree
Sai Perez
Full Stack JavaScript Techdegree Student 13,388 Points

Still not working: "Download a completed example of the "many-to-many relationship" challenge."

I'm unable to download the completed example of the many-to-many relationship in order to figure out how to do it. I read the documentation for using a many to many association and attempted this:

movie.js

Movie.belongsToMany(models.Person, {
    through: 'ActorMovies',
    as: 'actor',
    foreignKey: {
        fieldName: 'actorPersonId',
        allowNull: false,
     },
});

person.js

Person.belongsToMany(models.Movie, {
    through: 'ActorMovies',
    as: 'actor',
    foreignKey: {
        fieldName: 'actorPersonId',
        allowNull: false,
    },
});

app.js

// Add Movies to the Database
console.log('Adding movies to the database...');
const movieInstances = await Promise.all([ 
    Movie.create({
        title: 'The Iron Giant',
        releaseYear: 1999,
        directorPersonId: bradBird.id,
        actorPersonId: vinDiesel.id,
    }),
    Movie.create({
        title: 'The Incredibles',
        releaseYear: 2004,
        directorPersonId: bradBird.id,
        actorPersonId: craigTNelson.id,
    }),
]);

Please help.

1 Answer

Travis Alstrand
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Travis Alstrand
Treehouse Teacher

Hey Sai Perez ! :wave:

I'm very sorry about that inconvenience, there was a strange issue with the download link, but it has been fixed! You can try downloading the folder again and compare that with what you have now! :smiley:

If you still have any questions after comparing your code definitely feel free to reach back out on this post, I'll keep my eyes open just in case :thumbsup: