Forums / Developer / ezpersistentobject fetch function

ezpersistentobject fetch function

Author Message

Claudia Kosny

Monday 06 November 2006 3:14:29 pm

Hi there

I had to write my own datatype which writes some data into an additional table. I am trying to use the ez database abstraction using expersistentobject. The problem I have now is that the fetch function which is used in the constructor of expersistentobject is not defined in the expersistentobject class so I have no example for what to do in my class. When I check the code in other classes that extend ezpersistentobject the fetch functions are to different to know what is really necessary.

Currently I use this for my function fetch:

    function &fetch($rowId, $asObject)
    {
      return eZPersistentObject::fetchObject( eZChannelRelation::definition(),
                                                null,
                                                array( "id" => $rowId),
                                                $asObject );
    }

This seems to work fine but I would like to have some confirmation or correction as this is a major project.

So could someone point me to more information about the usage of ezpersistentobject?

The definition of my persistentobject looks like this:

    function definition()   
    {                       
        return array( "fields" => array( "id" => array( 'name' => 'id',
                                                        'datatype' => 'integer',
                                                        'default' => 0,
                                                        'required' => true ),
                                         "create_time" => array( 'name' => "createTime",
                                                                 'datatype' => 'integer',
                                                                 'default' => '',
                                                                 'required' => true ),                                         
                                         "creator_id" => array( 'name' => "creatorId",
                                                                 'datatype' => 'integer',
                                                                 'default' => 0,
                                                                 'required' => true ),
                                         "channel_id" => array( 'name' => "channelId",
                                                               'datatype' => 'integer',
                                                               'default' => 0,
                                                               'required' => true ),
                                         "expert_id" => array( 'name' => "expertId",
                                                               'datatype' => 'integer',
                                                               'default' => 0,
                                                               'required' => true ),
                                         "price" => array( 'name' => "price",
                                                               'datatype' => 'float',
                                                               'default' => 0,
                                                               'required' => true ),
                                         "status" => array( 'name' => "status",
                                                               'datatype' => 'integer',
                                                               'default' => 0,
                                                               'required' => true ) ),
                      "keys" => array( "id" ),
                      "increment_key" => "id",
                      "function_attributes" => array('channel_name' => 'channelName'),
                      "sort" => array( "id" => "asc" ),
                      "class_name" => "eZChannelRelation",
                      "name" => "my_expert_channel_relation" );
    }

Thanks

Claudia