CCK - 1 to many situation
gmclelland - August 13, 2007 - 17:29
I am trying to create a small application for a police department.
I have a criminal content type with a name and description, etc. How can I add multiple offenses to a criminal? Each offense has it's own fields like "victim sex", "victim age", "length of sentence", etc...
Also, how can I display a list of all the offenses the criminal has committed on the criminal's node page?
Is there any modules you would recommend?
Thanks for your help,
Glenn

These modules
Views, editview (or editablefields) and CCK
Views
Use views to show the offences on the node page. You can use Viewfield to add the view as a CCK field in your content nodes. You can also use insert_view filter to add views directly in your body text.
Of course you can use fields in your templates, use the get_view
Editview
Use editview to make blocks containing views with editable fields. Read the module page for more info and a good example. (Except on my system it works good for edits, but not so good for inserts, yet)
You might try out addnode to create child nodes automatically. Works well in some cases.
CCK
It seems you're using it already, but just to make sure. CCK can be used to make individual fields.
Check out this thread as well: http://drupal.org/node/82415
Paul K Egell-Johnsen
These modules
Views, editview (or editablefields) and CCK
Views
Use views to show the offences on the node page. You can use Viewfield to add the view as a CCK field in your content nodes. You can also use insert_view filter to add views directly in your body text.
Of course you can use fields in your templates, use the get_view
Editview
Use editview to make blocks containing views with editable fields. Read the module page for more info and a good example. (Except on my system it works good for edits, but not so good for inserts, yet)
You might try out addnode to create child nodes automatically. Works well in some cases.
CCK
It seems you're using it already, but just to make sure. CCK can be used to make individual fields.
Check out this thread as well: http://drupal.org/node/82415
Paul K Egell-Johnsen
Good Stuff
Thanks Paul,
That is the direction I was needing. I will give those a shot. Could Views Fusion be used as well? Which of the two modules would you use in a project? Addnode looks like it no longer has a maintainer.
I found something better
Nodeformpopup This one is exactly what I needed. Under each nodereference autocomplete field it will place a link with the name of the datatype (haven't tried multiple datatypes though) that you can reference. Pressing that link pops up a window and Bob's your uncle.
The perfect solution. Works well with multiple values as well as required values. Drop Addnode and Editview. They are hard to use and doesn't integrate well with your form. Especially Addnode is hard to use. Both are marked as not production ready. Nodeformpopup is.
I haven't had the chance to try out Editablefields it looks promising, in as much as I can make views where I can mass edit nodes. I'll see if it is possible. Editview did that, but only for simple types, it doesn't recognize the autocomplte fields for nodereferences, so it gets useless for the kind of edits I need to make.
Paul K Egell-Johnsen
Editablefields
I tried out Editablefields and it works pretty well, except that I can't insert tags in the view. If I select Taxonomy: Page tags field and add it to the field list, it will not be shown in a page which is handled through Editablefields. However, if I assign the same tags through nodereference (using the Categorymodule and autocomplete fields, then it works very well.
Unfortunately, then I have to add views to all my category and container nodes in order to show the children correctly, loosing a lot of the nice functionality that already is in the module. I've filed a feature request on this.
Another thing with Editablefields is that if I edit a page where I have exposed some filters, it doesn't seem to remember the filter settings after a submit, thus I can't see the result at once. I've filed a bug report on this.
The good thing is that the module is under continuous development, and it seems to be updated pretty often.
I was a bit harsh about Editview, yes, it doesn't integrate into your form, actually the recommended way is to use a block, but you could theme it, I'm sure. I had problems making it submit the data I added and keep the reference to the node I submitted from; I don't know if anything was submitted or not (my memory is a bit diffuse on that).
The good thing about the module is that mass import in the Quotes module doesn't seem to call all the hooks needed for the Automatic nodetitles module. So for me to get the right nodetitles, I have a simple Editview with just the titles of the nodes, filtered by those with a name of "ant". Then I just need to press update on each with a wrong title, and voilá, they are corrected.
That saves me from going into the node to get the titles correctly; unfortunately no module I've tried allows me to multiedit tags for nodes very fast, so I ahve to go in and edit each node anyway. Aaaargh.
Paul K Egell-Johnsen
Haven't tried it
Ok, I've used the nodefamily module and installed the Views Fusion, unfortunately I haven't had the time to test it out. From what I understand I should be able to make a view fusing two distinct views which are somehow linked through the nodefamily (or similar module). Exactly what I will gain from that, I don't know, yet. I have found that I can use ordinary views for most of my needs, but there might be some cases where a node is member of two other nodes which are a parent-child in a hierarchy. Thus it might be that I want to have the node shown just under the child and not in the parent, in order to build a page where parent will list all children with their nodes + all nodes assigned solely to the parent.
Paul K Egell-Johnsen
Node Relativity
Node Relativity I have it installed, but never went into it. Inside there are settings like:
Enforce Parental Rules
If checked, nodes cannot be created without a parent if they require a parent to exist.
Use Taxonomy to attach nodes
If checked, nodes cannot be attached if they don't belong to a taxonomy term. When listing nodes to attach, possible children will be displayed in a taxonomy tree.
This might be the "magic bullet" you need for your 1-n relationships, and probably n-n relationships and lots of other stuff. I'm playing with it, I'll let you know if there are interesting results :)
Paul K Egell-Johnsen
BTW: A peek at what I'm doing
http://beta.parroter.com shows you what I'm doing. I have to redesign the data structure (again) since I need to use Taxonomy Fields to implement polymorphy correctly. I want to have my sources polymorphic. But before I do that I'm going to get rid of the current system and just store info as plain text in the source node, then I'll add the extra features later; just so that I can start importing data and start using the site.
http://www.parroter.com/ is a previous iteration of the website.
I also think I got a solution to my woes with the Category module; I'm going to use the nodereference all the time. I remembered that the Categories, or Containers, from the Category module can embed views insead of their default presentation. Hopefully those can be defaulted for specific category types so that all new tag-categories will use the same view with a different argument suited to show all the tagged data.
Paul K Egell-Johnsen
Thanks Paul
Editablefields seems to do the trick.
I got the criminal's offenses to appear on the criminal's node page by adding this
if (arg(0) == 'node' && is_numeric(arg(1))) {
$criminal = node_load(arg(1));
if ($criminal->nid) {
return array($criminal->nid);
}
}
to the arguments of my view.
I am able to add/edit an offenses on a criminal's add/edit page ONLY if that criminal has offenses. If that criminal doesn't have any offenses then I am stuck with just the table headers of the view and no add/edit form for the offenses.
That's were I am stuck right now.
This is the code I am using on the block's visibility page:
<?phpif (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') {
$node = node_load(arg(1));
if ($node->type == criminal) {
return true;
}
}
return false;
?>
Let me know what you think. I need to figure out how to display the add form for the offenses on the criminals add/edit page when there is no nodereferences (offenses) for that criminal.
Thanks for your help,
Glenn
Sorry for the delay
I hope you got past your problems. I had to put my development efforts on the backburner because I started full time studies in addition to my full time job.
My final foray into this ended up using nodeformpopup, it is bundled with Node Family, If I'm not mistaken. When you build the relation in Node Family (for example criminal->offenses) then you get an option in the content/types/criminal where you can have "Shortcuts for nodereference fields:". So when you add a nodereference field in Criminal to Offenses, you will get a small textual link under the input form which will open a popup for you to add new offenses.
It still is far from perfect, because your offenses has more in common with tags than with tables in a database; because you can not say that the new offense you are making is unique for only this instance of an offender (and thus have some kind of cascading on delete, on creation etc).
Instead this offense will be available in all future node-reference fields.
Thus the Editablefields would be the preferred way of doing this, except it should be more like nodeformpopup in its useage.
Hmm, the problem I'm experiencing is more that I need to create the "criminal" first. Then I have to edit the "criminal", use the nodepopup to create an "offense", the offense must have a nodereference to "criminal", which will be the one I just made. The nodereference from "criminal" to "offense" must be a view, which will only list all those offenses which are referring to the current criminal.
That might solve my problems; and perhaps some of yours?
Anyway, I'm going to drop the use of the Quotes module, and instead make quotes as a plain vanilla cck datatype using only the core functionality, then I'm going to make an import function as per this description.
Paul K Egell-Johnsen