(collection, parent, connector)
| 759 | @private |
| 760 | */ |
| 761 | quote(collection, parent, connector) { |
| 762 | // init |
| 763 | const validOrderOptions = [ |
| 764 | 'ASC', |
| 765 | 'DESC', |
| 766 | 'ASC NULLS LAST', |
| 767 | 'DESC NULLS LAST', |
| 768 | 'ASC NULLS FIRST', |
| 769 | 'DESC NULLS FIRST', |
| 770 | 'NULLS FIRST', |
| 771 | 'NULLS LAST' |
| 772 | ]; |
| 773 | |
| 774 | // default |
| 775 | connector = connector || '.'; |
| 776 | |
| 777 | // just quote as identifiers if string |
| 778 | if (typeof collection === 'string') { |
| 779 | return this.quoteIdentifiers(collection); |
| 780 | } |
| 781 | if (Array.isArray(collection)) { |
| 782 | // iterate through the collection and mutate objects into associations |
| 783 | collection.forEach((item, index) => { |
| 784 | const previous = collection[index - 1]; |
| 785 | let previousAssociation; |
| 786 | let previousModel; |
| 787 | |
| 788 | // set the previous as the parent when previous is undefined or the target of the association |
| 789 | if (!previous && parent !== undefined) { |
| 790 | previousModel = parent; |
| 791 | } else if (previous && previous instanceof Association) { |
| 792 | previousAssociation = previous; |
| 793 | previousModel = previous.target; |
| 794 | } |
| 795 | |
| 796 | // if the previous item is a model, then attempt getting an association |
| 797 | if (previousModel && previousModel.prototype instanceof Model) { |
| 798 | let model; |
| 799 | let as; |
| 800 | |
| 801 | if (typeof item === 'function' && item.prototype instanceof Model) { |
| 802 | // set |
| 803 | model = item; |
| 804 | } else if (_.isPlainObject(item) && item.model && item.model.prototype instanceof Model) { |
| 805 | // set |
| 806 | model = item.model; |
| 807 | as = item.as; |
| 808 | } |
| 809 | |
| 810 | if (model) { |
| 811 | // set the as to either the through name or the model name |
| 812 | if (!as && previousAssociation && previousAssociation instanceof Association && previousAssociation.through && previousAssociation.through.model === model) { |
| 813 | // get from previous association |
| 814 | item = new Association(previousModel, model, { |
| 815 | as: model.name |
| 816 | }); |
| 817 | } else { |
| 818 | // get association from previous model |
no test coverage detected