2014-07-14 12 views
5

Waterline'ın SQL birleştirmelerini gerçekleştirmek için herhangi bir desteği var mı (query() dışında)? Modellerimde dernekler kurdum, ancak oluşturulan gerçek SQL sorguları select deyimleri döngüdür. Şu anda sadece "n + 1 select" için destek var mı? Bir yerde bir yapılandırma seçeneği eksik mi? İşte Sails Waterline SQL birleştirme grubuna katıl

seçme ifadeleri döngü bir 1-> Birçok populate bir örnektir: (yelkenler/su hattı/yelkenler-mysql v0.10.0-RC8) Ben http://localhost:1337/country?populate=[Cities] gidin Sonra

/** 
* City.js 
*/ 
module.exports = { 
"adapter": "someMysqlServer", 
"tableName": "city", 
autoCreatedAt: false, 
autoUpdatedAt: false, 
schema: true, 
attributes: { 
    "id": { 
     "type": "integer", 
     "primaryKey": true, 
     "autoIncrement": true, 
     "columnName": "ID" 
    }, 
    "Name": { 
     "type": "string", 
     "maxLength": 35 
    }, 
    "District": { 
     "type": "string", 
     "maxLength": 20 
    }, 
    "Population": { 
     "type": "integer" 
    }, 
    "CountryCode": { 
     //a city has one country 
     "model": "Country" 
    } 
}}; 




/** 
* Country.js 
*/ 

module.exports = { 
    "adapter": "someMysqlServer", 
    "tableName": "country", 
    autoCreatedAt: false, 
    autoUpdatedAt: false, 
    schema: true, 
    attributes: { 
     "id": { 
      "type": "string", 
      "required": true, 
      columnName: "Code", 
      "primaryKey": true, 
      "maxLength": 3 
     }, 
     "Name": { 
      "type": "string", 
      "maxLength": 52 
     }, 
     Continent: "string", 
     "Region": { 
      "type": "string", 
      "maxLength": 26 
     }, 
     SurfaceArea: "float", 
     IndepYear: "integer", 
     Population: "integer", 
     LifeExpectancy: "float", 
     GNP: "float", 
     GNPOld: "float", 
     LocalName: "string", 
     GovernmentForm: "string", 
     HeadOfState: "string", 
     Capital: "integer", 
     Code2: "string", 
     Cities: { 
      //country has many cities 
      "collection": "City", 
      "via": "CountryCode" 
     } 
    } 
}; 

benim günlükleri aşağıdaki sql idam edildi gösterir: beta .populate() uygulama kasten adaptörleri olabildiğince geniş kümesini desteklemek için basitleştirilmiş

SELECT `country`.`Name`, `country`.`Continent`, `country`.`Region`, `country`.`SurfaceArea`, `country`.`IndepYear`, `country`.`Population`, `country`.`LifeExpectancy`, `country`.`GNP`, `country`.`GNPOld`, `country`.`LocalName`, `country`.`GovernmentForm`, `country`.`HeadOfState`, `country`.`Capital`, `country`.`Code2`,`country`.`Code` FROM `country` LIMIT 30 OFFSET 0 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ABW' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='AFG' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='AGO' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='AIA' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ALB' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='AND' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ANT' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ARE' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ARG' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ARM' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ASM' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ATA' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ATF' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='ATG' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='AUS' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='AUT' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='AZE' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BDI' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BEL' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BEN' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BFA' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BGD' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BGR' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BHR' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BHS' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BIH' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BLR' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BLZ' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BMU' LIMIT 30 
SELECT `city`.`Name`, `city`.`CountryCode`, `city`.`District`, `city`.`Population`, `city`.`ID` FROM `city` WHERE `city`.`CountryCode`='BOL' LIMIT 30 
+0

Aynı problemi alıyorum. ? Populate = [model] url'yi kullanırsam sınamanın aynı davranışı elde ederim. Ben açıkça Model.find() populate ('OtherModel') çağrısı, biraz daha daha iyi bir sürümü (IN kullanarak) almak, ancak hala birleştirme. – Rowan

cevap

1

. Son v0.10 sürümünde, desteklenen "çekirdek" SQL bağdaştırıcıları (sails-mysql ve sails-postgresql) gerçek birleştirme yapacak.

+0

@ sgress454Bu güncelleme var mı? Ben sadece 0.10.2 ve yelken-mysql 0.10.4 yelken kurdu ve mysql günlükleri aşağıdaki çıktıyı gösterir: '(SELECT * FROM şehir şehir WHERE CountryCode =" ABW "SİPARİŞ BY city.id ASC LIMIT 30) UNION (SELECT * FROM) şehir AS şehir WHERE CountryCode = "AFG" SİPARİŞ BY city.id ASC LIMIT 30) BİRLİĞİ (SELECT * şehirden AS şehir WHERE CountryCode = "AGO" SİPARİŞ BY city.id ASC LIMIT 30) (...) ' – jaredfromsubway

+0

çünkü varsayılan 30 kayıt sınırı olan bir plan rotasına basıyorsunuz. Bu durumda basit bir katılım yapamazsınız, çünkü sorgu yalnızca 30 satır döndürür. Gerçekten istediğinizi 900 satır kadardır (30 ülke, her biri 30 şehir). Bu nedenle, her ülke için ayrı bir sorgu yapmaktan daha iyi olan 'UNION '. Bunu tek bir sorguya kadar kaynatırsanız, onu görmek çok isteriz! Hakkında daha fazla bilgi için [bu makaleye bakın] (http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/) adresine bakın. sorun. – sgress454