CoursePark / KnexNest

A wrapper for Knex.js that can output list of objects hydrated from a select
76 stars 10 forks source link

column reference "id" is ambiguous #10

Open siberiadev opened 4 years ago

siberiadev commented 4 years ago

When I'm trying get data like the code bellow:

let query = knex.select([
        'u.id as _id',
        'u.firstName as _firstName',
        'u.avatar as _avatar',
        'u.lastName as _lastName',
        'u.gender as _gender',
        'u.userStatus as _userStatus',
        'u.dob as _dob',
        'u.email as _email',
        'u.phone as _phone',
        'u.roleId as _roleId',
        'u.password as _password',
        'u.rating as _rating',
        'u.menthorRating as _menthorRating',
        'u.marathonsCompleted as _marathonsCompleted',
        'u.marathonsCreated as _marathonsCreated',
        'u.youtube as _youtube',
        'u.instagram as _instagram',
        'u.createdAt as _createdAt',
        'u.updatedAt as _updatedAt',
        'u.deletedAt as _deletedAt',
        'u.lastName as _user_lastName',
        'm.id as _mar_id',
        'm.title as _mar_title',
        'm.description as _mar_description',
        'm.category as _mar_category',
        'm.price as _mar_price',
        'm.userId as _mar_userId',
        'm.priceType as _mar_priceType',
        'm.programElementName as _mar_programElementName',
        'm.peoplePased as _mar_peoplePased',
        'm.peopleCounter as _mar_peopleCounter',
        'm.launchedTimes as _mar_launchedTimes',
        'm.status as _mar_status',
        'm.startDate as _mar_startDate',
        'm.adminComment as _mar_adminComment',
        'm.createdAt as _mar_createdAt',
        'm.updatedAt as _mar_updatedAt',
        'm.deletedAt as _mar_deletedAt'
    ])
    .from('users as u')
    .leftJoin('marathons as m', 'm.userId', 'u.id').where({id: id})

    console.log('QUERY', query)
    return await knexnest(query).then((data) => {
        return data
    })

I get this error: column reference "id" is ambiguous Is it issue for knexnest?

shosanna commented 4 years ago

Isn't the problem in the where clause, where you have {id: id} but you are not saying which id it is, from which table? I am not sure, I am a newbie trying to use this lib as well and I am having other problems myself :D