Code Monkey home page Code Monkey logo

cake-mongo's People

Contributors

dilab avatar giboow avatar josegonzalez avatar thomaswebermuc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cake-mongo's Issues

Entity validation

Hi,
I can not use the entity validation system. For example, $validator->notEmpty ('myfield', 'message');
Can you give an example?

Simple Find doesn't work

This simple code doesn't work

        $this->loadModel('Pages', 'Mongo');
        $pages = $this->Pages->find('all')->where(['parent'=>'root'])->limit(10);
        $page = $this->Pages->newEntity();

I see that Dilab\CakeMongo\Query::compileQuery is returning:

[
	'limit' => (int) 10,
	'filter' => [
		'parent' => 'root'
	]
]

But MongoDB\Collection expects filter without filter key and limit is a searchOption:

    /**
     * Finds documents matching the query.
     *
     * @see Find::__construct() for supported options
     * @see http://docs.mongodb.org/manual/core/read-operations-introduction/
     * @param array|object $filter  Query by which to filter documents
     * @param array        $options Additional options
     * @return Cursor
     * @throws UnsupportedException if options are not supported by the selected server
     * @throws InvalidArgumentException for parameter/option parsing errors
     * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
     */
    public function find($filter = [], array $options = [])

So rewriting compileQuery as the following code make a simple find works:


    public function compileQuery()
    {
        if ($this->_parts['fields']) {
            $this->_searchOptions['projection'] =
                array_combine($this->_parts['fields'], array_fill(0, count($this->_parts['fields']), 1));
        }

        if ($this->_parts['limit']) {
            $this->_searchOptions['limit'] = $this->_parts['limit'];
        }

        if ($this->_parts['offset']) {
            $this->_searchOptions['skip'] = $this->_parts['offset'];
        }

        if ($this->_parts['order']) {

            $this->_searchOptions['sort'] = collection($this->_parts['order'])->map(function ($item) {

                $key = key($item);

                $order = $item[$key];

                return [
                    'key' => $key,
                    'order' => ($order['order'] == 'desc' ? -1 : 1)
                ];

            })->reduce(function ($carry, $item) {

                $carry[$item['key']] = $item['order'];

                return $carry;

            }, []);

        }

        if ($this->_parts['filter']) {

            $this->_mongoQuery = array_reduce($this->_parts['filter'], function ($carry, AbstractFilter $filter) {
                $filterArray = $filter->toArray();
                $carry = array_merge($carry, $filterArray);
                return $carry;
            }, []);

        }

        return $this->_mongoQuery;
    }

fix-simple-find.patch.gz

Where to put databse config with what key?

Hi,

I have a question about database configuration. In your document, you write example only className and driver to pit in data sources so my question is where do I put database config and with what key?

Thanks in advance.

Undefined class constant 'BUILD_VALIDATOR_EVENT'

If you try to edit or to add an object in your database, you could have this error:

Error: Undefined class constant 'BUILD_VALIDATOR_EVENT'
File C:\wamp64\www\bob_dilab\vendor\cakephp\cakephp\src\Validation\ValidatorAwareTrait.php
Line: 176

I added the class constant in file vendor\dilab\cake-mongo\src\Collection.php:
const BUILD_VALIDATOR_EVENT = 'Model.buildValidator';

Its the same value than in the file vendor\cakephp\cakephp\src\ORM\Table.php

I don't know if it is the right way to fix it but it made the trick for me.

Disable Entity for Mongo ?

Hey, i'm using a Mongo and a MySQL database at the same time.
My virtual fields are not working for my MySQL tables, I think that the mongo configuration of the entities is
overwriting the default config.

Any solution ?

porting to CakePHP 3.3

Can you please port this to work with CakePHP 3.3.
Or can you help me doing it, I'm new to Cake.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.