(collection, parent, connector)
| 867 | @private |
| 868 | */ |
| 869 | quote(collection, parent, connector) { |
| 870 | // init |
| 871 | const validOrderOptions = [ |
| 872 | 'ASC', |
| 873 | 'DESC', |
| 874 | 'ASC NULLS LAST', |
| 875 | 'DESC NULLS LAST', |
| 876 | 'ASC NULLS FIRST', |
| 877 | 'DESC NULLS FIRST', |
| 878 | 'NULLS FIRST', |
| 879 | 'NULLS LAST' |
| 880 | ]; |
| 881 | |
| 882 | // default |
| 883 | connector = connector || '.'; |
| 884 | |
| 885 | // just quote as identifiers if string |
| 886 | if (typeof collection === 'string') { |
| 887 | return this.quoteIdentifiers(collection); |
| 888 | } |
| 889 | if (Array.isArray(collection)) { |
| 890 | // iterate through the collection and mutate objects into associations |
| 891 | collection.forEach((item, index) => { |
| 892 | const previous = collection[index - 1]; |
| 893 | let previousAssociation; |
| 894 | let previousModel; |
| 895 | |
| 896 | // set the previous as the parent when previous is undefined or the target of the association |
| 897 | if (!previous && parent !== undefined) { |
| 898 | previousModel = parent; |
| 899 | } else if (previous && previous instanceof Association) { |
| 900 | previousAssociation = previous; |
| 901 | previousModel = previous.target; |
| 902 | } |
| 903 | |
| 904 | // if the previous item is a model, then attempt getting an association |
| 905 | if (previousModel && previousModel.prototype instanceof Model) { |
| 906 | let model; |
| 907 | let as; |
| 908 | |
| 909 | if (typeof item === 'function' && item.prototype instanceof Model) { |
| 910 | // set |
| 911 | model = item; |
| 912 | } else if (_.isPlainObject(item) && item.model && item.model.prototype instanceof Model) { |
| 913 | // set |
| 914 | model = item.model; |
| 915 | as = item.as; |
| 916 | } |
| 917 | |
| 918 | if (model) { |
| 919 | // set the as to either the through name or the model name |
| 920 | if (!as && previousAssociation && previousAssociation instanceof Association && previousAssociation.through && previousAssociation.through.model === model) { |
| 921 | // get from previous association |
| 922 | item = new Association(previousModel, model, { |
| 923 | as: model.name |
| 924 | }); |
| 925 | } else { |
| 926 | // get association from previous model |
no test coverage detected