I have a relation type to which I added a required date field with the default value set to 'now'. When I create a new relation entity programmatically, I want the date field to also be created and to be set with the default value.

I use the following code to create the new relation entity programmatically:

  $endpoints = array(
    array('entity_type' => 'user', 'entity_id' => $account->uid),
    array('entity_type' => 'node', 'entity_id' => $session)
  );
  $relation = relation_create ('has_log_with', $endpoints);
  $rid = relation_save($relation);

The code above creates the new relation entity, but it does not contain a date field set with the default value. What function(s) should I call to make this happen? Thanks!

Comments

chx’s picture

Title: How to programmatically create a relation entity and setting fields » Required fields are not attached on relation_save
Assigned: Unassigned » chx
Category: support » bug
Priority: Normal » Major

Thanks for reporting this bug. I will try to figure out why this doesn't happen. It should.

mikran’s picture

naught101’s picture

Status: Active » Closed (duplicate)

Let's just merge these - I've already started work on test for this over there anyway.