embeddedDocument in an embeddedDocument problem

67 views
Skip to first unread message

Brian Kristoforus

unread,
Aug 3, 2011, 9:09:27 AM8/3/11
to YiiMongoDbSuite
Hi guys !

I have Style class embedded in Template class which is embedded in
User class.
{User
{Tempate
{Style
styleAttr : attrVal
}
}
}

I can easily save the data using $user->template->style->styleAttr
pretty easily.
I checked the database and the data is saved properly.

However, when I tried to retrieve the data, the attributes values of
the Style are missing.
I checked the source code and it seems that setAttributes from CModel
class is the culprit.

I just overridden this function from EMongoEmbeddedDocument class for
temporary solution.
Is this a bug ? Or did I miss something here ?

Any suggestion would be most appreciated. Thank you.

Cheers !

--

Brian

Masaru Hoshi

unread,
Aug 3, 2011, 9:23:13 AM8/3/11
to yiimong...@googlegroups.com
Hey Brian,

I had quite this same problem yesterday. I had something like this:

World {
  items: [
    Item : {
      Position: {
        x: integer,
        y: integer,
        z: integer
      }
    },
    ...
  ],
  ...
}

I had Position as an Embedded Document of Item, which is another Embedded document. I noticed when I retrieved the World object, Position attributes were always null. Just to make it short, I made it work overriding the rules method like this:

    public function rules() {
        return array(
            array('x, y, z', 'required'),
            array('x, y, z', 'numerical', 'integerOnly' => true),
        );
    }

I still don't know why, but it's now working.

Cheers.

2011/8/3 Brian Kristoforus <bhbr...@gmail.com>



--
Mr. Masaru Hoshi | Senior Software Analyst | ho...@hoshi.com.br

This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy,  disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.

このメッセージは機密および/または特権情報を含むかもしれない。受信人または受信人のためのこれを受け取るために承認されてでなければこのメッセージか情報にここに基づく処置を使用するか、コピーするか、表わすか、またはとってはならない。間違いのこのメッセージを受け取ったら、送り主に応答の電子メールによってすぐ助言し、このメッセージを削除しなさい。あなたの協同をありがとう。

Brian Kristoforus

unread,
Aug 3, 2011, 9:45:05 AM8/3/11
to YiiMongoDbSuite
Hi Hoshi-san !

thank you for your response.

I know why it is working.. It is because when you are retrieving
document, this function is involved :
public void setAttributes(array $values, boolean $safeOnly=true),
where safeOnly is boolean whether the assignments should only be done
to the safe attributes. A safe attribute is one that is associated
with a validation rule in the current scenario.

By default, safeOnly will be set true, that's why your model will
returns the correct values.
I think the model should returns correct value even if we don't set
the rules.

You might not understand what I'm talking about since I'm not really a
good at explaining. But you will when you try to look at the source
code :D

cheers !

--

Brian

> 2011/8/3 Brian Kristoforus <bhbray...@gmail.com>

Mayur Ahir

unread,
Oct 1, 2011, 4:23:53 AM10/1/11
to yiimong...@googlegroups.com
Hi Guys,
I have structure like this,

{User extends EMongoDocument
{CompensationBasic extends EMongoEmbeddedDocument
{CompensationAllowances extends EMongoEmbeddedDocument
type:
amout
}
{CompensationDeductions extends EMongoEmbeddedDocument
type:
amout
}

}
}

But I always get error as
Event "CompensationBasic.onBeforeSave" is not defined.

Attila Nagy

unread,
Oct 3, 2011, 4:48:00 AM10/3/11
to yiimong...@googlegroups.com

Hi, could you please send a backtrace?

Do you use any other behaviors? EEmbeddedArraysBehavior earlier had a
bug, that casued an error message like yours.


--
Nagy Attila Gabor

Message has been deleted
Message has been deleted

Mayur Ahir

unread,
Oct 4, 2011, 2:42:18 AM10/4/11
to yiimong...@googlegroups.com
Here is the link for error traceback.
http://www.diigo.com/item/image/193y2/j60t

Attila Nagy

unread,
Oct 5, 2011, 11:53:27 AM10/5/11
to yiimong...@googlegroups.com
On Tue, Oct 4, 2011 at 8:42 AM, Mayur Ahir <ahir...@gmail.com> wrote:
> Here is the link for error traceback.
> http://www.diigo.com/item/image/193y2/j60t

sorry, your previous two emails were empty (for me), and this link is
404. You might simply paste the trace into an email.

--
Nagy Attila Gabor

Mayur Ahir

unread,
Oct 5, 2011, 2:25:07 PM10/5/11
to yiimong...@googlegroups.com

Sorry I had made link private plz check the screenshot agian in case its still 404

Attila Nagy

unread,
Oct 7, 2011, 4:19:05 AM10/7/11
to yiimong...@googlegroups.com

Hi!

Thanks, now I see the problem. This is a bug in the mainline suite, that has already been fixed, but since canni had no more time to support this package, it did not get merged yet. The current release version of YMDBS does not support arrays in embedded documents.
I would recommend that you use my testing branch, here:
https://github.com/mrbig/YiiMongoDbSuite/tree/testing
it contains lots of bug fixes, and improvements. We're currently building a large project based on this codebase, so it seems to be stable to me.

If you don't want to diverge this much from the master branch, you might just use the fix for your bug from this branch:
https://github.com/mrbig/YiiMongoDbSuite/tree/b/recursive_arrays


On Wed, Oct 5, 2011 at 8:25 PM, Mayur Ahir <ahir...@gmail.com> wrote:

Sorry I had made link private plz check the screenshot agian in case its still 404



--
Nagy Attila Gabor
Reply all
Reply to author
Forward
0 new messages