Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Juan Leñero
    @juanjoLenero
    and then overriding the collections _prepareModel method to set the language on instantiated models
    Katharina Irrgang
    @kirrg001

    Hey 👋 We (two Ghost developers - ErisDS and kirrg001) were invited to collaborate. Thanks for invitation.

    We just merged one PR, see tgriesser/bookshelf@7191132
    Is there a chance to release a new version this week?That would be great :)

    Burak Cankurtaran
    @Uptown76

    I'm trying to model the following SQL using Bookshelf. I want to get all the clients for a particular developer, where a developer has many apps and a client can belong to many apps.

    select distinct client.*
    from client
    inner join client_app
    on client_app.client_id = client.id
    inner join app
    on client_app.app_id = app.id
    inner join app_developer
    on app_developer.app_id = app.id
    inner join developer
    on app_developer.developer_id = developer.id
    where developer.id = 1

    Screen Shot 2016-11-10 at 11.41.57 AM.png
    Not quite sure how to go about this. I can explain more, if someone is willing to help.
    Rocky Assad
    @CodisRedding
    Unhandled rejection TypeError: this._reset is not a function at Builder.CollectionBase (/Users/rocky.assad/code/services/srv-lab/node_modules/bookshelf/lib/base/collection.js:46:8)
    I’m getting this error on save (with new and Forge)
    Rocky Assad
    @CodisRedding
    nvm, got it
    I was forging/newing an already new’d Model
    Jon
    @BadQuanta
    So, if you want to compute a virtual attribute value based on information in associated/related models; is there a guide to that anywhere? I'm kinda stumped and am thinking of resorting to having the virtual attribute return a promise... but that makes the serialized() data messy.. :/
    Nick Acker
    @ackerdev
    Are there any options for explicitly defining attribute lists on models? I'd like to map column<->attribute names, whitelist attributes, and define validation rules.
    I can probably hack around it with things like parse/format, but is there any built-in way of doing this or any solid community plugins?
    blah238
    @blah238
    @ackerdev I haven't used it but check out https://github.com/bogus34/bookshelf-schema
    Nick Acker
    @ackerdev
    Yeah, I've seen that one, and it's not too shabby but not really quite enough for what I'm looking for
    blah238
    @blah238
    In what way (just curious, like I said not familiar with it myself)?
    Nick Acker
    @ackerdev
    As far as I can tell, it doesn't allow you to rename the model attributes, and the validation is a little awkward/limited
    and afaik you still need another plugin for whitelisting which isn't terrible but isn't great either
    blah238
    @blah238
    Looks like you can pass a column option to the field definition which sets which DB column the attribute corresponds to: http://bookshelf-schema.readthedocs.io/en/latest/fields.html
    Nick Acker
    @ackerdev
    ah, good catch.
    Nick Acker
    @ackerdev
    @blah238 After tinkering with it a bit more, I'm still left unsatisfied with the schema plugin. I still don't much care for the api, and there are some odd behaviors like JSON.stringify(model) and model.toJSON() no longer being equivalent (bookshelf-schema seems to overwrite toJSON, but doesn't do so correctly causing the schema-fields to not actually be represented if using stringify. Just doesn't feel like a really well made plugin, unfortunately. I might look into making something of my own at this point.
    darkghoul79
    @darkghoul79
    how is computed fields handled on bookshlef?
    for example on ratings. wanted to get review count, total reviews, etc. but i wanted those info to be an attribute of the model. is that even possible? tried using virtuals plugin but mostly works of getters/setters.
    any suggestions would be greatly appreciated. thanks.
    Roshan Bhalla
    @rbhalla
    Is there a nice way to have the relations have join conditions? I.e. I'd love to be able to do something like ModelA.hasOne(ModelB).where('type', 'foo)
    Roshan Bhalla
    @rbhalla
    It's possible this was the wrong forum for a question, and I haven't been able to solve it so I've reposted the question at http://stackoverflow.com/questions/42472384/join-conditions-on-relationships
    If you know how it'd really help :)
    Gratian
    @Gratiandev
    Hi, I'm new to knex and I have a problem, could anyone translate for me this sql query into knex query? SELECT * FROM password_resets LEFT JOIN users on users.username = ? WHERE user = users.id AND code = ?
    simonecogno
    @simonecogno
    It's easy with knex knex().select('*').from('pasw_reset as pr').leftJoin('users', 'users.username', 'passw_reset.username').where('pr.user.id', 'users.id').where('pr.user.code', 'users.code').toString();
    Result in "select * frompasw_resetasprleft joinusersonusers.username=passw_reset.usernamewherepr.user.id= 'users.id' andpr.user.code= 'users.code'"
    I actually having problem on writing the same query on bookshelf by using the relations without using knex joins
    Nitish Phanse
    @nitish24p
    Hey i had the following question
    a withRelated : table-name does not create an explicit left join instead it chains the ids found in the parent table as a select * from table-name where id in [Huge array of ids]. So there are 2 queries being fired. Isnt this a performance issue..
    i've raised an issue on github too explaining my problem in detail
    tgriesser/bookshelf#1544
    Any help here would be nice :)
    darkghoul79
    @darkghoul79
    Been trying to use .through and seems like it is not using the otherKey.. instead it is using idAttribute.. anyway to override?

    Model Setup

    orders
     - id
     - buyerId
    
    items
     - id
     - orderId
     - ownerId
    
    users
     - id
     - name

    In orders model i have:

    buyer() { // which works perfectly
      return this.belongsTo('User' , 'buyerId', 'id')
    }
    
    owner() { // which does not work
      return this.belongsTo('User' , 'buyerId', 'id').through("Items"), 'id', 'orderId')
    }
    darkghoul79
    @darkghoul79
    the owner method generates this sql:
    select `users`.*, `items`.`id` as `_pivot_id`, `items`.`ownerId` as `_pivot_ownerId` from `users` inner join `items` on `items`.`ownerId` = `users`.`id` inner join `orders` on `items`.`id` = `orders`.`id` where `orders`.`id` in (?)
    which is wrong.. notice the join between orders and items.. should have been
    inner join `orders` on `items`.`orderId` = `orders`.`id`
    and not inner join `orders` on `items`.`id` = `orders`.`id`
    darkghoul79
    @darkghoul79
    any help/alternative solution would be nice.
    darkghoul79
    @darkghoul79

    I was able to tweak it in order generate the right query,

    owner() {
        // return this.belongsTo('User', 'buyerId', 'id') .through("Items"), 'id', 'orderId')
        const relation = this.belongsTo('User', 'buyerId', 'id') .through("Items"), 'id', 'orderId')
    
        relation.relatedData.throughIdAttribute = 'orderId'
        return relation
      }

    But unfortunately, its not returning owner info/record.

    Georgy Shabunin
    @twist900
    hi, is it possible to use bookshelf with oracle db?
    simonecogno
    @simonecogno

    I have some issue with fetching related models of a model.
    The model definition is this:

    app.database.Model.extend({
            tableName: 'variation_score',
    
            variations: function() {
                this.belongsToMany(app.models.Variation)
            }
    }

    And I would like to fetch the variation later in my code like this:

    new app.models.VariationScore({id: variationScore.id})
                    .fetch({withRelated:{variations: function (qb) { qb.column('name') }}})
                    .then(viariationScoreWithVariations=> {
                             console.log(viariationScoreWithVariations);
                   });

    But the related models are not fetched correctly. Any ideas how to do it?

    I also tried:

    .fetch({withRelated: 'variations'})
    .fetch({withRelated: ['variations']})

    But also don't work.

    Oli Lalonde
    @olalonde
    Hola
    What's the recommended way to store data on models that shouldn't be persisted?
    directly as a property?
    tomoat
    @tomoat
    How use where …in in bookshelf ?
    Georgy Shabunin
    @twist900
    @tomoat should be where('column_name', 'in', ['stuff1', 'yo'])
    or .query((qb) => qb.whereIn('column_name', ['stuff1', 'stuff2']))
    Georgy Shabunin
    @twist900
    Does anyone know how to deal with the following problem. I eager load related models using withRelated in fetch, and it works perfectly - thanks bookshelf/knex team. My question is how can I eager load only certain relations, instead of all. Example case: I need to fetch an Author with only his latest published Book. Using .fetch(withRelated: [{ books: (qb) => qb.max('publish_date') }] ) will run .max on all of the Books tables, but I need max value between those related to that Author.