Relation_create has been changed to be a wrapper around relation_construct and relation_save. While relation_save returns the RID (not the full object, for some reason), relation_create does not.

I also think the full relation object should be returned rather than the ID, but that's just me ;)

CommentFileSizeAuthor
#1 relation_create_save-1337740-1.patch358 bytesAnonymous (not verified)

Comments

Anonymous’s picture

StatusFileSize
new358 bytes

Attached is a one-liner fix.

tenken’s picture

Just my 2 cents ... I believe the mentality in the Drupalverse is that [node|entity|term]_save() return IDs, not full objects.

So you have 2 options now:

  • hand make a relation to get a new RID via construct() and save()
  • OR "save and forget" if your mass creating simple relations, via create()

I make many relations with attached fields so I do the 1st scenario often and add fields between consruct() and save() ...

I suppose it may not hurt to return a RID on create(), but then some confusion may arise between save() and create()'s purposes ...

Anonymous’s picture

@tenken - Agreed about returning IDs; however, things in the Drupalverse are not so consistent. For example, node_save accepts the node object by reference, so you can always get the nid from the object after calling node_save, while comment_save returns nothing, and user_save returns the full user object.

I do use relation_construct -> relation_save when creating relations that are fieldable, but oftentimes a relation is just the endpoints and that's it.

I guess it's not terribly detrimental to have nothing returned, but in the interest of saving a few lines of code here and there, this might be a good little addition.

chx’s picture

Status: Active » Closed (fixed)

I reverted the construct - create change.