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

Jump to content

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

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

#1 User is offline   Sammaye 

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

Posted 27 February 2013 - 01:29 PM

This is the place to discuss the MongoYii extension: http://www.yiiframew...nsion/mongoyii/

You can also file a GitHub issue as usual: https://github.com/S...MongoYii/issues
1

#2 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

Posted 27 February 2013 - 03:44 PM

Thanks for the discussion topic.

Quote

Ah yes it shows that it returns "users" by default in the example (@example), hmm that's a bit misleading?

Whoops - I did not associate the comment with the "@example" - Mainly because this annotation is new to me, and there is a line break between the annotation and the example itself.

Quote

Ha, nice spot with that, there was a space before the "function" where I was meant to put in the "private" but never did

Thats cool - but these functions are spread all over the classes. Adding the access scope modifiers would be nice :).

I got two more things to add to my list that i wrote in the comment section earlier:
Named Scopes
Are these supposed to work? I cannot use the standard approach to define a named scape.
e.g.
public function type($myType)
{
    $crit = new EMongoCriteria(array('condition' => array('attr' => $myType)));
    $this->getDbCriteria()->mergeWith($crit); <-- FAILS. $this->getDbCriteria() is an array, not an object!

    return $this;
}

Also if I try it the other way around - $crit->mergeWith($this->getDbCriteria()) - it is not working because the dbCriteria is possibly just NULL.

EMongoDocument::getPrimaryKey()
I know that the primary key - at this stage - is not supposed to change. But if you could add a method to return the value of the primary key (just like CActiveRecord::primaryKey) i could use this in my code to ensure that i get the correct value.
I don't know if this makes sense because at this stage of the extension it would return just the "_id" property as hardcoded value. Since I am not that much into MongoDB I also don't know if it is common to change the name of the PK to something else.
0

#3 User is offline   Sammaye 

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

Posted 27 February 2013 - 04:49 PM

Quote

Thats cool - but these functions are spread all over the classes. Adding the access scope modifiers would be nice


How do you mean?

In models using this extension this function should only exist in one place, in the EMongoDocument.

Quote

Are these supposed to work? I cannot use the standard approach to define a named scape.


I wish I had taken out the criteria class now.

It doesn't work with the merging in scopes, they are completely array based.

If I am honest I only added the EMongoCriteria class in case there was something I was missing about it.

Hmm yea I have changed the way to define scopes, I should add that to the documentation with an example. Basically I have taken out the criteria object from it entirely.

Quote

EMongoDocument::getPrimaryKey()


Aye I can do that: https://github.com/S...11900631e033d7b
0

#4 User is offline   Sammaye 

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

Posted 27 February 2013 - 05:20 PM

I have added a note about custom scopes now: http://www.yiiframew.../mongoyii/#hh18

If you want to use the code shown there you will need to update your checked out version, I added an extra function to aid in merging criteria easily.
1

#5 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

Posted 27 February 2013 - 05:53 PM

View PostSammaye, on 27 February 2013 - 04:49 PM, said:

How do you mean?

In models using this extension this function should only exist in one place, in the EMongoDocument.


I mean that many functions within your extension lacks of the (private/protected/public) access scope modifier
EMongoModel::__construct()
EMongoModel::attributeNames()
EMongoClient::init()
EMongoClient::connect()
Almost the whole EMongoCursor class
to name a few.

Thanks a lot for your insane fast responses and implementations. Named scopes helps me a lot :). Too bad that the aggregation framework is not supported somehow. But I understand that it isn't fitting well into AR :(.
0

#6 User is offline   Sammaye 

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

Posted 28 February 2013 - 03:26 AM

Hmm I could always add a aggregation helper to the model so that you don't have to use the mongodb object directly, that should at least make the collection names more modular within the app and also hopefully that should be all accessors plugged in now :)

https://github.com/S...90e1e4c988bb1ba

Thanks for the awesome testing you have been doing, it has really helped :D
0

#7 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

Posted 28 February 2013 - 03:53 AM

If a shortcut like MyCollection::model()->aggregate() instead of Yii::app()->mongodb->MyCollection->aggregate() makes sense, I would be glad to have this implemented. Otherwise I am totaly fine with the extension at this point :).
0

#8 User is offline   Sammaye 

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

Posted 28 February 2013 - 04:01 AM

Indeed so you can just call the model and not have to type in the collection name directly like, as you said:

User::model()->aggregate(array(
    array('$group'=>array('_id'=>'$username','sum'=>array('$sum'=>1)))
));


It is there as well:

https://github.com/S...988bb1ba#L3R637

Was in the last commit :)

Awesome! Thanks again for testing
1

#9 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

Posted 28 February 2013 - 05:26 AM

Just tested the named scopes and I found a Bug there.

Lets say I've Collection::model()->scope()->find(); the scope applies some conditions to the criteria.

Now if I call Collection::model()->getDbCriteria() I expect to have a totaly new model and therefore an empty criteria. But to my suprise the criteria from the scope is still present in the criteria of the new model!

BTW: Could you add an alias for findBy_id and name it findByPk - So it can be used the Yii way ;).
0

#10 User is offline   Sammaye 

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

Posted 28 February 2013 - 05:34 AM

Indeed I did notice that about scopes. Originally I thought it was a bug but I apply scopes like Yii does so I eventually just said that maybe it is a Yii thing (those parts are actually a straight copy from CActiveRecord). I will take a new look into that now that I kow it ain't.

Added the Alias :)
0

#11 User is offline   Sammaye 

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

Posted 28 February 2013 - 05:46 AM

Ok I think I found the bug.

I checked CActiveRecored again and it turns out that when Yii queries and it calls "applyScopes" it also resets them in that function so that the cached static instance of the model is never effected by finds() etc.

Should be fixed now.
0

#12 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

Posted 28 February 2013 - 05:48 AM

Amazing how fast you are - Seems to be working :)
0

#13 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-May 09

Posted 28 February 2013 - 01:18 PM

Using EMongoDataProvider with CListView reveals an other small bug. Yii expects the data returned from CDataProvider::fetchData() to be index based. Currently its an associative array where the key is representing the PK of the document.

The fix is very simple: In EMongoDataProvider:108 change this line
return iterator_to_array($this->_cursor);

to
return iterator_to_array($this->_cursor, false);

in order to generate an index-based array.
0

#14 User is offline   Sammaye 

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

Posted 28 February 2013 - 01:47 PM

Indeed I do believe that function should return a index-based array, commited :)
0

#15 User is offline   rAWTAZ 

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

Posted 08 March 2013 - 08:45 PM

Surely there must be a way to put both a composer compatible autoloader in the source tree, so that this can be put on packagist? I'm not sure I see how there would be a conflict with that one and the regular Yii autoloader, the latter which would simply be loading classes as usual and the composer one wouldn't be used in this case. Thoughts?
0

#16 User is offline   Sammaye 

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

Posted 09 March 2013 - 09:24 AM

I must admit I haven't ever used composer, I only briefly looked into it. I am looking into composer support for this extension now.
0

#17 User is offline   rAWTAZ 

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

Posted 09 March 2013 - 07:51 PM

Great, thanks :) I think it's super easy, just have a look at https://github.com/Crisu83/yii-less or some other one of Crisu's extensions to see an example.

I've recently started using Composer and it's a real breeze to just add a line in your 'require' array and run `composer update` and have it all managed for you. Also easy to set up namespaces and autoloading.
0

#18 User is offline   Sammaye 

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

Posted 10 March 2013 - 05:57 AM

Indeed that is very simple, I don't even need to use the composer autoloader if I just have to provide configuration like that.

I'll look into completing this today.

I have written a composer.json file now which should work but whenever I attempt to upload it to the packagist site it keeps saying they had a problem their end, I try to clean my browser session and re-log in but then I get a 500 error :\.

So it will be up as soon as that gets fixed
0

#19 User is offline   Sammaye 

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

Posted 10 March 2013 - 06:08 AM

Ha typical, as soon as I say that it works: https://packagist.or...ammaye/mongoyii
0

#20 User is offline   Agrail 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 11-June 12

Posted 17 March 2013 - 05:23 AM

Thanks for great extension, Sammaye.
Is there an easy way to display validation errors of embedded documents and embedded arrays through CHtml::errorSummary($model) or CHtml::error($model)? How do you realize validation process in your applications?
0

Share this topic:


  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 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