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>