HELP!!

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
BMS_Steve's picture

New to the group and Drupal, having an issue and haven't found anywhere else that can help with a solution. I have asked on 'drupal.stackexchange.com' but nothing.

If this is the wrong place to ask, forgive me and delete.

I have a table {cases} which has in part, upload_id, case_id and case_name-- etc etc.
The field upload_id has been serialized.
When a user goes to a form and uploads a file, if it is a new case, meaning case_name is NOT present then get max(case_id) add one and save to database.

Also users can add a file to existing cases, so the upload_id would auto-increase because it is serial, and the case_id stays the same.

So the question is; how to insert the case_id to begin with?

I've been working on this one area for 2 weeks and have come to the end of my noose.

AttachmentSize
diagnostic module.doc26.5 KB

Comments

Welcome!

danlinn's picture

Hello!

This is probably not the best place, but it's probably not the worst either.

It seems from your post that you're interacting directly with the database, which in a lot of cases (Possibly including this one) isn't needed. Based on the limited info I have, I would create a Case node type, and let users submit those. That will take care of all the auto ID stuff for you, allowing you to focus on the UX and content. Maybe I'm misunderstanding, but if you're interacting with the DB this early in your Drupal experience, you're likely barking up the wrong tree.

I'm guessing this invalidates a lot of what you may have done already, which is never fun. If you like, as a consolation prize, I'd be happy to sit down with you, give you a chance to explain what it is you're trying to build, and tell you how I would do it in Drupal. I am at Mentorship Saturdays (http://meetup.com/Mentorship-Saturdays) almost every week and would be happy to meet you there.

Another option would be to go to the local Brewpal meetup (3rd bullet here https://groups.drupal.org/portland) and ask for assistance there.

Thanks,
Dan

Welcome +1

timhare's picture

I'd have to agree with Dan. One of the hardest parts, for me, about learning Drupal has been mentally letting go of the database and letting Drupal handle that all behind the scenes.

When the user "goes to a form and uploads a file", in Drupal what he's doing is "creating content". The form that he goes to is the form for creating a new node of type "case". File uploads can be taken care of by a field of type File with a cardinality greater than 1. Or, if you need, you can create a parent/child relationship between cases and file uploads, where a "file upload" is a content type of its own.

What is the url of the

frob's picture

What is the url of the stackoverflow question. It is always nice to link all the questions together so others who might find this can find the actual answer.

I would want to know more about the use-case before assigning it to an existing entity type. Content (or nodes) is an existing entity type. Seeing as how you are dealing with files and uploads it might make sense to use the file entity and then link the case content entity to the original upload.

As a part of the original question. Is the case_id an auto_increment field?

URL link

BMS_Steve's picture

http://drupal.stackexchange.com/questions/206858/conditionally-increment-a-case-id/207887#207887

The auto_increment is upload_id and has a relationship to case_id of M:1.

We would need to have the

frob's picture

We would need to have the schema and the code in order solve the question as you are asking. Are you attempting to write both records at the same time or is the case record being created separately? Is the case_id a proper foreign key or just an int field. What method are you using to write this record?

Generally you just need to do this order of steps:

check for case name:

If no case name is found;
then
create case and get case_id;
else
just get the case_id from the existing case;

write new file record.

Without code I don't know how much more help we can be. Really though, use Drupal for this. There are times that a table can just be a table, but this looks to be more complicated than just a table. Drupal has a whole entity system designed to handle these things for you.

Rebuild your data structures in Drupal using Drupal. After you have done that, then if you have existing data use the migrate module to import that data.