小编St0*_*0rM的帖子

Laravel:一对多对多,检索distinct()值

Laravel 4项目,使用Eloquent ORM.

我有三个表:客户,订单和产品(+ 1个数据透视表order_product).客户与订单一对多关联.订单与产品多对多关联.

Customers  1-->N  Orders  N<-->N   Products
Run Code Online (Sandbox Code Playgroud)

我想在Customer模型上有一个方法来检索客户正在购买的产品列表.

为了更好地理解这一点,假设产品是消耗品.

例如,客户#1可以放置:

  • 产品A,B和C的订单#1;
  • 产品A,C和D的订单#2;
  • 产品C和E的订单#3;

...我想要检索的结果是带有产品A,B,C,D和E的集合.

模型是(在运行中伪编码):

class Product extends Eloquent {

    public function orders()
    {
        return $this->belongsToMany('Order');
    }

}

class Orders extends Eloquent {

    public function customer()
    {
        return $this->belongsTo('Customer', 'customer_id');
    }

    public function products()
    {
        return $this->belongsToMany('Product');
    }

}

class Customers extends Eloquent {

    public function orders()
    {
        return $this->hasMany('Orders', 'customer_id');
    }

    public function products()
    {
        // What to put here ???
    }

}
Run Code Online (Sandbox Code Playgroud)

laravel laravel-4

8
推荐指数
2
解决办法
5113
查看次数

找到一个点在3d空间中的位置移动矢量与均匀的圆周运动

假设我在3d空间中有一个点A,我想用单位向量n周围的均匀圆周运动来移动它.

所以我知道A,O的位置向量和单位向量n(垂直于O,A和B所在的平面),我知道角度AOB.

找到B的位置最快的方法是什么?

math 3d geometry

7
推荐指数
1
解决办法
1427
查看次数

使用automake安装配置文件和日志文件

假设我有一个这样的项目:

(dev dir)
- README
- INSTALL
/ src
  - blah.cpp
  - blah.hpp
/ conf
  - blah_one.xml
  - blah_two.xml
Run Code Online (Sandbox Code Playgroud)

我创建了一个configure.ac和Makefile.am来在(/ usr/local)/ bin下安装二进制文件.configure.ac是这样的:

AC_INIT([blah], [0.1])
AC_PREREQ([2.67])
AM_INIT_AUTOMAKE([1.11])
AC_CONFIG_SRCDIR([src/blah.cpp])
AC_PROG_CXX
AC_LANG([C++])
AC_HEADER_STDC
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_OUTPUT
Run Code Online (Sandbox Code Playgroud)

...... Makefile就像

SUBDIRS = src
Run Code Online (Sandbox Code Playgroud)

...和src/Makefile.am类似

bin_PROGRAMS = blah
blah_SOURCES = blah.cpp blah.hpp
Run Code Online (Sandbox Code Playgroud)

一切正常,"make install"正确安装(/ usr/local)/ bin下的二进制文件.

现在:

我想扩展这些命令"make install"(在configure,build之后),在/ etc/blah下安装配置文件blah_one.xml和blah_two.xml,并在/ var/log下"准备"一个日志目录/废话/

这样做的正确方法是什么?

automake

5
推荐指数
1
解决办法
5347
查看次数

std ::具有奇怪行为的boost :: mutex的地图

我有这个代码:

////
// Default Namespaces
///

using namespace std;

typedef map <string, boost::shared_mutex>   t_map_shared_mutex;

int main(int argc, char** argv) {

    t_map_shared_mutex  list_lock;

    boost::shared_mutex global_lock;

    string          i = "ABC";

    boost::unique_lock < boost::shared_mutex > l_lock ( global_lock );

    boost::unique_lock < boost::shared_mutex > lock ( list_lock[i] );
        //Do Something with that lock
    lock.unlock();

    l_lock.unlock();

}
Run Code Online (Sandbox Code Playgroud)

这会生成以下错误.根据我的理解(我可能在这里非常错误)g ++告诉我,互斥量是作为const值传递的......我不明白为什么.

In file included from /usr/include/c++/4.4/utility:63,
                 from /usr/include/boost/config/no_tr1/utility.hpp:21,
                 from /usr/include/boost/config/select_stdlib_config.hpp:33,
                 from /usr/include/boost/config.hpp:40,
                 from /usr/include/boost/date_time/compiler_config.hpp:12,
                 from /usr/include/boost/date_time/posix_time/posix_time.hpp:14,
                 from prova.cpp:5:
/usr/include/c++/4.4/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-thread

5
推荐指数
1
解决办法
1797
查看次数

"或"和"||"之间的区别

两者之间有什么区别吗?

if ( a or b or c ) {
Run Code Online (Sandbox Code Playgroud)

...和...

if ( a || b || c ) {
Run Code Online (Sandbox Code Playgroud)

......在两个运营商之间,甚至在优先级方面更多?

c++

5
推荐指数
1
解决办法
224
查看次数

标签 统计

c++ ×2

3d ×1

automake ×1

boost ×1

boost-thread ×1

geometry ×1

laravel ×1

laravel-4 ×1

math ×1