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

Jump to content

  • (6 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6
  • You cannot start a new topic
  • You cannot reply to this topic

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

#61 User is offline   Sammaye 

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

Posted 27 September 2013 - 05:03 AM

Indeed let me think about this: https://github.com/S...oYii/issues/125 I need to think of what it could break and why it was done like that etc etc.
0

#62 User is offline   Sammaye 

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

Posted 27 September 2013 - 06:19 AM

This trials the fix: https://github.com/S...eases/tag/2.3.0
0

#63 User is offline   elke 

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

Posted 27 September 2013 - 06:45 AM

Thank you very much for your quick and constructive response!

Maybe you could suggest to me something for another difficulty with dubdocuments? Because I really start to rethink of using them.

For example I have a subdocument named "en" with title, text, and some additional attributes, which are not displayed in the edit form.
When I populate model with POST data
$model->attributes = $_POST['News'];

I lose all attributes from subdocument which were not added to the form.

I can:
1. Add all data to the form in hidden fields, but it's auxiliary data, which I do not want to show on a page.
2. Change names of form fields, so POST data won't replace subdocument, but I will have to rename attributes in model's labels, validation rules, manually assign attribute values in form and before saving, etc.

Or there is an easier way, which I don't see?
0

#64 User is offline   Sammaye 

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

Posted 27 September 2013 - 06:49 AM

If you wish for a more complicated subdocument I would consider using an actual class instead of the subdocument validator.

The validator can only do so much automatically before it starts to flounder. It simply cannot understand the context of complex work flows, I left this understanding upto using actual class based subdocuments.

So I would split you subdocuments out into classes because I would say they are comlpex enough, the subdocument validator is good at automating very simple and basic subdocuments but anything more and you wanna use something a but more complicated.
0

#65 User is offline   elke 

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

Posted 27 September 2013 - 07:02 AM

I actually use class for some subdocuments. But the problem is the same that the method of setting attributes is replacing subdocument (object or array) with incomplete data from a form. It assigns values not to the separate subfields in subdocument, but takes an array from POST data and assigns it to subdocument attribute.
0

#66 User is offline   Sammaye 

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

Posted 27 September 2013 - 08:14 AM

It is? Is this using the subdocument validator or actually doing it manually via building the array and appending its elements?

Because that's what I meant.

I mean there is one idea if making the subdocumentvalidator aware of the subdocuments current entries if that is what your using.
0

#67 User is offline   Sammaye 

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

Posted 27 September 2013 - 08:16 AM

I am however unsure how easy or secure or stable it would be to add the change to the subdocumentvalidator though, when you start getting into this sort of territory you should be doing the subdocuments manually really.

Only you know the context
0

#68 User is offline   Sammaye 

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

Posted 27 September 2013 - 10:24 AM

I also hit a snag with pogrammably setting the labels for subdocuments. Yii uses the function attributeLabels() and only that function, unfortunately in PHP you cannot actually programmably define the contents of a function.

There is a couple of ways around it but both are hacky and could be nasty:

- Override Yii itself potentially causing breakages in the future by changing getAttributeLabel()
- create a map inside of the created model, this would require huge amount of recursion.

There is another way. In the model you can define:

array('profile','subdocument','type'=>'one','rules'=>array(
array('title','length','max'=>12,'tooLong'=>'Second title is bad'),
array('url','url')
)),

And in the attribute labels you can define:

array(
'profile[title]'=>'Second title'
)

And that would actually do everything you want.

The latest push should support that
0

#69 User is offline   varchun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 01-October 13

Posted 01 October 2013 - 11:25 AM

I am new to Yii, so excuse me for a stupid question.

Try test connection. Wrote
Yii::app()->mongodb


and got
include(Mongo.php): failed to open stream: No such file or directory


What I've done incorrect?
0

#70 User is offline   Sammaye 

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

Posted 01 October 2013 - 11:40 AM

Are you sure you have installed the php driver? http://php.net/manua...nstallation.php
0

#71 User is offline   varchun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 01-October 13

Posted 01 October 2013 - 12:07 PM

Yes....But i wrote "xtension" in php.ini

Thanks! You save a lot of my nerve ))
0

#72 User is offline   elke 

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

Posted 03 October 2013 - 08:22 AM

Hello, Sammaye!

Could you please add the populateRecords() method to the EMongoDocument class? It can be quite useful after MongoDB aggregation to convert an array of records from the result to an array of objects of specific class.

There is EMongoDocument::populateRecord() for 1 record, but in Yii's CActiveRecord class there is also the mothod for array of records. Example from Yii:
public function populateRecords(array $data, $callAfterFind = true, $index = null)
{
    $records = array();
    foreach ($data as $attributes) {
        if (($record = $this->populateRecord($attributes, $callAfterFind)) !== null) {
            if ($index === null) {
                $records[] = $record;
            } else {
                $records[$record->$index] = $record;
            }
        }
    }
    return $records;
}

0

#73 User is offline   Sammaye 

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

Posted 03 October 2013 - 08:31 AM

Done and added to 2.4.0 cheers: https://github.com/S...eases/tag/2.4.0
0

#74 User is offline   elke 

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

Posted 03 October 2013 - 09:37 AM

Thank you! Already in use )
0

#75 User is offline   elke 

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

Posted 08 October 2013 - 09:41 AM

Hello, Sammaye.

Have you thought to implement migration algorithm for MongoDB in your extension?
MongoDB is structureless, but there are still indices that need to be ensured. And there might be a necessity to remove old attributes or add new ones in bulk.
0

#76 User is offline   Sammaye 

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

Posted 08 October 2013 - 09:48 AM

That sounds like a whole new extension in itself in many ways.

I havent thought about it becaue many times it is considered a bad idea to merely migrate, you should redesign for MongoDB.
0

#77 User is offline   redfox 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 14-June 11

Posted 21 October 2013 - 09:47 AM

View Postelke, on 08 October 2013 - 09:41 AM, said:

Hello, Sammaye.

Have you thought to implement migration algorithm for MongoDB in your extension?
MongoDB is structureless, but there are still indices that need to be ensured. And there might be a necessity to remove old attributes or add new ones in bulk.


Hi elke,

i already had a lot of thoughts regarding this topic. I opened an issue on github some days ago (github.com/Sammaye/MongoYii/issues/146), if you got some other ideas, don't hesitate to leave your thoughts there or contact me. Im really interested in how other people face this issue.
0

#78 User is offline   elke 

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

Posted 22 October 2013 - 04:47 AM

Hi, redfox,

I've read the issue on github and I'm not sure I like the technique of getters for changed attributes. It's a definite way to a large, unmanageable legacy code, difficult to maintain in the future by people who won't know a thing about old db structure.

And there is still modification of indices, which cannot be added to the model.
During development I add new indices for new queries, and the person, who rolls out a new version, must have instructions which indices to ensure or delete. I also see it as a migration and would like to save this instructions beside the code in repo.

I think that I will implement something similar to Yii's migration algorithm. I've just started to use MongoDB with Yii, so my project is not big yet, but I already feel a problem here.
0

#79 User is offline   Sammaye 

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

Posted 22 October 2013 - 04:58 AM

I used to allow modifcation of indeces through the application but then I suffered a serious loss of data and uptime due to a newbie who inadvertantly messed up and made a very large index for the cluster rebuild itself.

So I am firmly against inplementing index functions in the models, it just asking for trouble with future generations of programmers.
0

#80 User is offline   Taff 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 31-October 13

Posted 31 October 2013 - 08:42 AM

I'm a bit of a newbie with Yii but have used multiple other frameworks on the past.

I'm trying to use two MongoDB collections in a relationship but aren't sure quite how to go about it. I've spent most of the day trying different things...to no avail.

I have 2 collections.

products (which should have multiple offers)
offers (which has one product)

Going off the Docs as I understand them:

    public function relations() {
        return array(
            'offers' => array('many', 'Offer', 'product_id'),
        );
    }


is in my products model.

Calling for example $products = Product::model()->find()->limit(50);

returns 50 products but no related offer data. I tried using with etc. etc.

According to the docs I need an on clause:

Quote

The default behaviour of relations is to attempt to use the primary key, _id, of the current model to query the foreign key. This is a problem for EMongoModel since it has no primary key. Make sure that if you use this in EMongoModel you define a on clause to replace the primary key of the current model.

The on clause supports multiple field types. It can take a DBRef or an ObjectId or an array of ObjectIds depending on how you define your document.


Does anyone have an example of an on clause and where it needs to go?

Thanks to anyone who can show me some light.

Cheers,
Taff
0

Share this topic:


  • (6 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6
  • 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