Forum OpenACS Q&A: "the right way" to store values from checkboxes in the CR?

Hi,

I am wandering about various bits of code in various packages and documentation... I'm looking for a smart/preferred way to store multiple values for a single attribute along with a content_type in the CR.

To be more concrete, what I'm doing specifically, is getting user input from a FORM and then inserting it into the CR as a new revision of a specific content_type. This works great. I create the content type with content_type__create_type and then I am able to generate a single SQL insert statement to create my revision.

Until I add checkboxes to my form. Then of course the multiple values for a single attribute blow my one-to-one mapping of attributes to table fields and my insert breaks.

What I'm trying to figure out is should I just create my own table for multiple values and do a separate insert "outside" of the CR API? Or is there a CR API for handling this situation that I'm just not seeing? Like I looked a photo-album package and the photos are created as a separate content_type in the CR and then related back to the photo_albums. This seems like a wacky way to handle multiple values from a checkbox: create a content_type for each attribute that could have multiple values (checkboxes)? Or create the checkbox attributes as generic storage attributes? I'm fumbling around here...

Can anyone else let me know how they handle storing multiple values for a single attribute in a content_type in the CR? If that is clear enough!

Tammy,

Looks like you need a mapping table. The content repository only stores some default attributes. If you need to store any additional attributes you need to create a table to store them.

If you have a one-to-many relationship between items and attribute values, you'll need a table that looks like this:

create table item_attribute_values (
    revision_id integer references cr_revisions,
    attribute_value varchar (or whatever is appropriate, possibly boolean)
);

THen you would store one row for each instance of the attribute for each item.

I haven't seen anyplace this is used, but it should work.

Usually there is just one value for each additional attribute.

I agree with Dave.  Just insert on your custom view, then insert on your mapping table.

Make it 2 inserts.

Thanks guys.

It'll be several inserts it looks like. I have several checkboxes with multiple values each. But it'll still work.

Seems like it's not really using the CR right to do it this way... it won't be totally generic and reproducible just by knowing the content_type and fetching from the content_typeX view but it will work. And I just want it to work right now!!