Call to a member function add() on a non-object

Hi  All,

                 I am having a custom module con_ProFormas

I have created a one to many relation ship to documents.

I want to attac a document to this custom  module

In my code i am using the following but getting an error.

$docbean = BeanFactory::newBean("Documents");
$docbean->name = 'Record';
$docbean->save();


$rel_name="documents";
$cp = new con_ProFormas();
$cp->retrieve($this->bean->id);
$cp->load_relationship($rel_name);
$cp->$rel_name->add($docbean->id);
$cp->save();
   

But i am getting an error like fatal Call to a member function add() on a non-object

Can any one please guide me where i am wrong.

Regards

SIdhu André Lopes Francesca Shiekh hats