Now that we have created an association between our Comments component and the previously created News component, a potential problem presents itself. What happens if a user deletes a News entry which contains one or more Comment entries (attached)? # define primary key attribute for news table $f_db_info_array['id'] = ( array ( 'db_field_name' => 'id', 'db_field_type' => 'int', 'db_field_length' => 3, 'db_primary_key' => TRUE,
# field is hidden from visibility at all times 'hidden_all' => TRUE )
# setup dependency information to clean all associated comments as well upon deletion 'db_dependency_tables' => array( array ( 'db_table_name' => 'comments', 'db_field_name' => 'news_id', 'db_display_name' => 'Comment' ) ), 'db_dependency_flush' => TRUE ); As you can see we've added two array keys to the 'id' descriptor array: 'db_dependency_tables' and 'db_depencency_flush'. The first, 'db_dependency_tables', contains an array of arrays - each array specifying information about a unique record dependency. Since only one dependency exists in our example application, only one array has been specified. The second variable, 'db_depencency_flush', contains a boolean value that tells Nennius how to act in the event that a News record (with one or more Comments records attached) is deleted. In our case we specified 'TRUE', which means that all associated Comments will also be deleted. (Note: If we had specified 'FALSE' then Nennius would have refused to delete any News releases with one or more User Comments attached.)
blog comments powered by Disqus |
|
|
|
|
|
|
|