Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-Referenced Many To Many #165

Open
asaf050 opened this issue May 16, 2016 · 4 comments
Open

Self-Referenced Many To Many #165

asaf050 opened this issue May 16, 2016 · 4 comments

Comments

@asaf050
Copy link

asaf050 commented May 16, 2016

Hello,

I'm trying to create a self-referenced many to many relationship but I keep getting 404 error.
I don't know if i'm doing something wrong or epilogue doesn't support it.

Here's the relevant code from my project:

// Define sequelize models
var AssemblyPart = sequelize.define('assemblypart', {
    quantity: {
        type: DataTypes.FLOAT,
        allowNull: false,
        validate: {
            notEmpty: true, // don't allow empty strings
            min: 0,
            isDecimal: true
        }
    }
});
var Part = sequelize.define('part', {
    part_number: {
        type: DataTypes.STRING,
        allowNull: false,
        validate: {
            notEmpty: true, // don't allow empty strings
        }
    },
    description: {
        type: DataTypes.STRING
    }
}, {
    paranoid: true,
    indexes: [
        // Create a unique index on part number
        {
            unique: true,
            fields: ['part_number']
        }
    ]
});

// Set up the relationship
Part.belongsToMany(Part, {
    as: 'ParentPartId',
    foreignKey: 'ParentPartId',
    through: AssemblyPart
});
Part.belongsToMany(Part, {
    as: 'ChildrenPartId',
    foreignKey: 'ChildrenPartId',
    through: AssemblyPart
});

// Setup the resources
epilogue.resource({
    model: Part,
    endpoints: ['/part', '/part/:id'],
    associations: true
});
epilogue.resource({
    model: AssemblyPart,
    associations: true
});
@mbroadst
Copy link
Collaborator

@asaf050 support for this is currently not implemented: #34 (comment)

@asaf050
Copy link
Author

asaf050 commented May 17, 2016

@mbroadst thank you for your answer.
There is any workaround for the meantime?

@mbroadst
Copy link
Collaborator

@asaf050 I'm not sure what you mean by "workaround"? Support is not implemented for auto associating self-referencing belongs-to-many relations, the workaround would be to implement support for that feature.

@Antiavanti
Copy link

Antiavanti commented Jun 20, 2016

👍 It will be really nice feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants