Hi Alex

Maybe you could give us a bit more info on the `html_contents` and
`fancy_scripts` tables, because my inclination would be just to have a
simple `contents` table.

This table would have three fields: (`id,`content_type`, `blob`) where:
* `content_type` is "HTML", "CGI" or "Module" (or rather, ids pointing to
the `target_type` table);
* `blob` is a base64 encoding of a structure containing both the data
(HTML, CGI or module) and any metadata such as URL parameters, class
attributes etc.

I would then be using DBIx::Class to access the table and have methods on
the Schema to decode and make use of `blob` appropriately depending on the
`content_type`.

Perhaps it would be easier to have two fields (`metadata`, `data`) instead
of `blob` but you get the idea.

Let me know if that's clear as mud, or I've missed the point altogether:)

Andrew



On Fri, Apr 10, 2015 at 6:04 PM, Alex Becker <asb.c...@gmail.com> wrote:

> Hi!
>
> This is not directly a Perl question, but since Perl is the only language
> I code in, I hope you could help me out.
>
> I have a database for a very simple Perl-based Web CMS.
> The CMS knows only 2 types of content: a HTML web site or a Perl module
> executing some fancy CGI script.
>
> So let's assume I have 3 tables:
> a) html_contents
> b) fancy_scripts
> c) navigation
>
> HTML contents is trivial. It's an excel-sheet-like table with a title and
> the HTML code.
>
> Fancy scripts work the same, except that it's maybe the URL to the CGI
> script, or a class name.
>
> Navigation however can hold 2 kinds of content: a reference to a row in
> the HTML contents table or a reference to one of those fancy scripts.
>
> How do I do that?
> My current approach is the following:
>
> Make the navigation table have 3 columns:
>  <id, target_type, target_id>
>
> target_type is an identifier for the kind of thing I reference. In the
> example, it could be fancy_script or content.
>
> But now I get a bad feeling because I can't really make the column
> target_it a foreign key that really is a reference to one of those tables
> (scripts or HTML).
> I usually always do it that way. I even normalize the target_type so that
> I have an extra table for target_types with a target type ID and an ident.
>
> Is there a standard approach for this kind of database table construct?
> A coding recommendation?
> Or am I doing it completely wrong?
>
> Best regards,
> Alex
>



-- 
Andrew Solomon

Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon

Reply via email to