Yii Framework Forum: [Extension] Mongoyii - Yii Framework Forum

Jump to content

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

[Extension] Mongoyii Rate Topic: -----

#21 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 17 March 2013 - 07:24 AM

It uses much the same setup as Yii but nested within the root document in array form. Hmmm, it seems that the error summary cannot just take a plain array which kinda sucks.

I might need to write an additional little function some where that can do what CHtml cannot.
0

#22 User is offline   rAWTAZ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 08-January 10

Posted 17 March 2013 - 07:36 AM

View PostSammaye, on 17 March 2013 - 07:24 AM, said:

It uses much the same setup as Yii but nested within the root document in array form. Hmmm, it seems that the error summary cannot just take a plain array which kinda sucks.

I might need to write an additional little function some where that can do what CHtml cannot.

CHtml::errorSummary() is designed to take instances of CModel, and EMongoModel extends from that class, hence it has getErrors() which is what errorSummary() use. What is the problem, can you not give it an instance of EMongoModel?

Also, I'd like to point out that EMongoModel shouldn't override getErrors() since it doesn't do anything that the parent equivalent doesn't do. Removing this (and potentially other overriding methods that does the same thing as parent) can clean up the class a bit :)
0

#23 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 17 March 2013 - 07:42 AM

Quote

What is the problem, can you not give it an instance of EMongoModel?


The problem is that subdocuments are not enclosed in EMongoModel classes, they are simply arrays and the error summary functions do not recognise array nesting for errors.

Quote

Also, I'd like to point out that EMongoModel shouldn't override getErrors() since it doesn't do anything that the parent


Yea, however, if you check the comments above it you will realise that I added a new method which modified a private variable in the parent. PHP OO accession works in such a way that if you want to modify a parent variable directly that is of private scope you cannot. You have to duplicate all the code associated with that var whose functionality you wish to keep.
0

#24 User is offline   rAWTAZ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 08-January 10

Posted 17 March 2013 - 07:48 AM

View PostSammaye, on 17 March 2013 - 07:42 AM, said:

Yea, however, if you check the comments above it you will realise that I added a new method which modified a private variable in the parent. PHP OO accession works in such a way that if you want to modify a parent variable directly that is of private scope you cannot. You have to duplicate all the code associated with that var whose functionality you wish to keep.

Gotha. Too bad. Hate redundancy :-)
0

#25 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 17 March 2013 - 08:04 AM

Indeed I hated the thought of it too :( if only Yii had getters and setters for direct manipulation of the errors var :(
0

#26 User is offline   rAWTAZ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 08-January 10

Posted 17 March 2013 - 08:04 AM

Can't you use a combination of getting and setting/complementing the errors from the parent?
0

#27 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 17 March 2013 - 08:08 AM

The only way to add errors to the var atm from the parent instance is to assume you are adding a message to a field and nothing else I don't think, unless you mean something else?
0

#28 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 20 May 2013 - 04:53 AM

To let people know, I will most likely start to remake MongoYii for Yii2 in the coming weeks/months (depending on how long it takes for the Yii team to say that the API etc is not going to change).

So I have full intention of porting MongoYii in its current form, hopefully without breaking too much, to Yii2
0

#29 User is offline   Ivo Pereira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 29-July 12

Posted 19 June 2013 - 06:55 AM

Is just me that the MongoCursor always returns empty whichever would be the collection?

I'm doing this:

<?php
echo '<pre>';

var_dump( Yii::app()->mongodb->historical->find() );

echo '</pre>';
?>


I'm sure the collection name historical and the db in the config are totally correct, and of course the collection has results.
0

#30 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 19 June 2013 - 06:57 AM

Due to how MongoDB works that won't get a cursor but instead a `MongoCollection` object. This is fundamentally how the PHP driver works. If you want a MongoCursor to return you will need to use a read function like `find` or `findOne`
0

#31 User is offline   Ivo Pereira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 29-July 12

Posted 19 June 2013 - 09:06 AM

View PostSammaye, on 19 June 2013 - 06:57 AM, said:

Due to how MongoDB works that won't get a cursor but instead a `MongoCollection` object. This is fundamentally how the PHP driver works. If you want a MongoCursor to return you will need to use a read function like `find` or `findOne`


I am afraid that's not happening to me.

Var_dump returning the following:

object(MongoCursor)#44 (0) {
}


And by analysing my code you can see that I'm using the method find() to return it.
0

#32 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 19 June 2013 - 09:07 AM

Yes it will only return a MongoCursor, what exactly are you trying to return? If you are trying to return all results from that collection then you can try `iterator_to_array($cursor)`
1

#33 User is offline   Ivo Pereira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 29-July 12

Posted 19 June 2013 - 09:38 AM

View PostSammaye, on 19 June 2013 - 09:07 AM, said:

Yes it will only return a MongoCursor, what exactly are you trying to return? If you are trying to return all results from that collection then you can try `iterator_to_array($cursor)`



That made it! I didn't even know about what iterators where. Gonna read more about it.

But, in another way how could I get that data without doing this? (as it was not mentioned elsewhere, I suppose there is another way of getting this data into a Yii view for example)

Thanks!

(by the way, I would recommend you to add a small note about it in the project Wiki and/or Github to help people that were looking specifically for this)
0

#34 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 19 June 2013 - 09:43 AM

The driver docs do a very good job of explaining all of its own features, if you read: http://php.net/manua...go.tutorial.php , more specifically: http://www.php.net/m...rial.cursor.php it should explain all the things not related to the MongoYii extension itself.
1

#35 User is offline   Ivo Pereira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 29-July 12

Posted 19 June 2013 - 10:51 AM

View PostSammaye, on 19 June 2013 - 09:43 AM, said:

The driver docs do a very good job of explaining all of its own features, if you read: http://php.net/manua...go.tutorial.php , more specifically: http://www.php.net/m...rial.cursor.php it should explain all the things not related to the MongoYii extension itself.


Thanks a lot :)
0

#36 User is offline   elke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-July 13

Posted 18 September 2013 - 03:04 AM

Hello.
I'm trying to migrate from MySQL (ActiveRecord) to MongoDB using MongoYii and I found that saveAttributes($attributes) method does not work like it does in AR. It should "save a selected list of attributes", where $attributes are "attributes to be updated".

But in MongoYii, saveAttributes() erases all other attributes which are not passed to this method.
class EMongoDocument extends EMongoModel{
    public function saveAttributes($attributes) {
        ...
        return $this->updateByPk($this->{$this->primaryKey()}, $values);


In my opinion, it should work like in update() method:
class EMongoDocument extends EMongoModel{
    public function update($attributes=null) {
        ...
        $this->lastError = $this->updateByPk($this->{$this->primaryKey()}, array('$set' => $attributes));


What do you think?
0

#37 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 18 September 2013 - 03:12 AM

Ouch that is definitely a bug
0

#38 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 24-June 11

Posted 18 September 2013 - 03:17 AM

I have added version 2.2.4 to the github repo which should incldue this fix now, thanks for reporting
0

#39 User is offline   elke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-July 13

Posted 18 September 2013 - 03:32 AM

View PostSammaye, on 18 September 2013 - 03:17 AM, said:

I have added version 2.2.4 to the github repo which should incldue this fix now, thanks for reporting

Thank you for a quick fix!
0

#40 User is offline   xproblem 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 13-August 12

Posted 25 September 2013 - 05:31 AM

Hi, Sammaye

I'm trying to update model by pushing an array, example

$attributes = array(
    'test' => 'message',
);
House::model()->updateByPk(
                new MongoId($id),
                array(
                    '$push' => array('history'=>$attributes)
                )
            );


But it always pushes this array 3 times. What's wrong with this update query?
0

Share this topic:


  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users