Forum OpenACS Development: To associate 2 content_types

Posted by Iuri Sampaio on
Hi there,

I need to create a relationship between pa_album and a custom content_type (i.e. ee_venue).

What'd be the best way to relate those content_types, through their items or objects?

I notice there's a ad_proc called content::item::relate, but its arguments item_id and object_id made me think twice if that ad_proc was intended to relate cr_items, but cr_items and acs_objects only.


Best wishes,

Posted by Antonio Pisano on
Hello Iuri

There is quite some machinery in the content repository to relate stuff to content items, but might be overkill in many cases.

A very generic, no rocket-science way to relate arbitrary acs-objects is the attachments package[1]. It is basically a two columns table referencing acs_objects (with proper on delete cascade defined in case one of the two objects gets deleted).

Hope this helps


Posted by Iuri Sampaio on

I was expecting to create a relation such as: using acs_rels to create role and type, as in this sample with videos and thumbs :
select acs_rel_type__create_role(
'video_object', --role
'Video', --pretty_name
'Videos' --pretty_plural

select acs_rel_type__create_type(
'video_image_thumbnail_rel', --rel_type
'#acs-subsite.Video_Image_Thumbnail#', --pretty_name
'#acs-subsite.Video_Image_Thumbnails#', --pretty_plural
'relationship', --supertype
'video_image_thumbnail', --table_name
'image_id', --id_column
'video_image_thumbnail_rel', --package_name
'content_item', --object_type_one
'video_object', --role_one
1, --min_n_rels_one
1, --max_n_rels_one
'content_item', --object_type_two
null, --role_two
0, --min_n_rels_two
1 --max_n_rels_two

Posted by Iuri Sampaio on
Hi there,

As one of other solutions, I've written the following chunks to acs_rels data model, plus I’ve added a few other glue codes along with item-add.tcl , photos-add and so on. All them within a new and customized page and package.

Is there any documentation/tutorial about how to use cr_items and revisions within custom packages?

I found none at:

From item_id to album_id
set album_id [relation::get_object_two -object_id_one $item_id -rel_type "ee_item_album_rel"]

and vice-versa
set item_id [relation::get_object_one -object_id_two $album_id -rel_type "ee_item_album_rel"]

Posted by Iuri Sampaio on
I guess I got it!

I wonder if there's a tutorial as in:

Best wishes,

Posted by Iuri Sampaio on
A suggestion:
we could add this thread as a new topic within the documentation

There's an item already, called as: Relating content to other objects.

This thread could be:
Relating content to other content items

Best wishes,

Posted by Dave Bauer on
If you control at least one of the objects/packages code you can always add a foreign key or a simply mapping table for many to many or one to many relations.

You can use acs_data_links for simple relationships also.

See acs-tcl/tcl/application-data-links-procs.tcl

Much simpler. If you are adding code to acs_rels you probably are making it more difficult than it needs to be.

Posted by Iuri Sampaio on
Right on! The ad_proc /api-doc/proc-view?proc=application_data_link%3a%3anew&source_p=1

is the one.

Thanks again Dave!