2008年10月21日星期二

Re: [fw-db] Re: Re: Re: Re[fw-db] ferencemap: delete CASCADE

In that case, you have two different data storages to work with - the database, and the hard disk drive. Your intention is to delete items from both of those storages where the items belong to article 123.

There are many approaches to this, but I think one way to handle this is to store your data on the hard disk drive in a manner similar to the way your database is set up. You can easily do one-to-many relationships in a file system:

/articles
    article_001
        comments
            comment_334
                picture.png
                graph.png
    article_002
        comments
            comment_51
                vacation.png
                brochure.jpg
            comment_88
                stuff.zip

This would be like a poor-man's cascade that would allow you to delete an article and everything that belongs to it with just one command. The same would be true in your database -- delete an article and all related comments (and their files [records]) go with it.

If you have a many-to-many relationship to the files, then you may want to go with a different directory structure... or store the data in the database as binary, but I don't recommend this.


On Tue, Oct 21, 2008 at 2:57 AM, EducatedFool <wimkumpen@hotmail.com> wrote:



Bill Karwin wrote:
>
> I would rather see cascading operations removed from Zend_Db
> completely.  It's not safe to implement cascading operations in client
> code, because it introduces race conditions.  That is, concurrent
> updates by other clients can interrupt a cascading operation, which
> can cause broken data integrity.
>
> Regards,
> Bill Karwin
>

Just a quick question I came up with...

I have a table where you can put comments on something and at every comment
I can upload multiple files. Something like this:

table_comments (id, title, comment, ...)
table_comment_files (id, comment_id, filename, path,...)

Let's say I build my constraints in my database. If I delete a comment, it
will also delete the records in the files table. But, then, it also needs to
delete the files from the server.
The only way I can do it, before I delete the comment, searching for files
and delete them from the server, hard coded. Or is there another way?
'Cause, let's say, if my comment is on an article. And I delete the article,
then I also have to look there if there are files on the comments, on that
article I want to delete...
View this message in context: http://www.nabble.com/Referencemap%3A-delete-CASCADE-tp20027817p20086177.html
Sent from the Zend DB mailing list archive at Nabble.com.




--
-Hector

没有评论: