1
來自沉重MySQL
和PHP
背景我不能真正理解這一點。處理流星角
我有一個branches
與ManytoOne關係Restaurants
(所以有很多分支機構連接到同一家餐廳)的集合。
這樣的關係由字段restaurantId
定義,其存儲對象的id。我branches
收集如下顯示:
{
"_id" : "uH4KbNYxw8cnCEqvk",
"address" : "1 High Street",
"loc" : {
"coordinates" : [
0.0,
0.0
],
"type" : "Point"
},
"restaurantId" : "dvxZ2NiA3gbevffsk"
}
,當然還有restaurants
現藏
{
"_id" : "dvxZ2NiA3gbevffsk",
"name" : "Restaurant name"
}
,我使用$near
查詢由接近下令所有的樹枝,我無法找到一個乾淨的在分支上循環時獲取父級餐廳名稱的方法。
這裏是我做過什麼 - 我的意思是,它的工作原理,因爲它是,但我認爲性能方面它有很多有待改進
// controller
angular.module("MyApp").controller("SearchRestaurantsCtrl",
function($scope, $stateParams, $meteor){
$meteor.subscribe('branches');
$meteor.subscribe('restaurants');
$scope.branches = $meteor.collection(function() {
return Branches.find({
loc: {
$near: {
$geometry: {
type: "Point",
coordinates: [ $stateParams.lng, $stateParams.lat]
},
$maxDistance: 300000
}
}
});
});
$scope.getRestaurant = function(restaurantId) {
return Restaurants.findOne({
_id: restaurantId
});
};
}
);
// view
<div ng-repeat="branch in branches">
<h3>{{getRestaurant(branch.restaurantId).name}}</h3>
<address>{{branch.address}}</address>
</div>