Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreign keys are not defined #42

Open
almasaeed2010 opened this issue Sep 17, 2018 · 5 comments
Open

Foreign keys are not defined #42

almasaeed2010 opened this issue Sep 17, 2018 · 5 comments

Comments

@almasaeed2010
Copy link
Contributor

organism_analysis table uses drupal schema to install the table which ignores the FK definition.

Possible solutions:

  1. Use entity delete hook to remove records
  2. Create the table using raw SQL

We'll also need an update function to remove deleted entities from the linker table.

@almasaeed2010
Copy link
Contributor Author

almasaeed2010 commented Sep 17, 2018

Steps to fix this:

  • Run an update function to clear organism_analysis from any missing records
  • Write an ALTER query to add the foreign keys with on delete cascade for both organism_id and analysis_id

@almasaeed2010
Copy link
Contributor Author

almasaeed2010 commented Sep 17, 2018

Query to find deleted analysis:

select * from chado.organism_analysis oa
 LEFT join chado.analysis a on a.analysis_id = oa.analysis_id 
 where a.analysis_id is null

@almasaeed2010
Copy link
Contributor Author

The query to add a foreign key is not working on my local dev. I am not sure why it fails on db_query but succeeds when its run in psql directly:

db_query('ALTER TABLE chado.organism_analysis
   ADD CONSTRAINT organism_analysis_organism_id_fk
   FOREIGN KEY (organism_id)
   REFERENCES chado.organism(organism_id)
   ON DELETE CASCADE')->execute();

  db_query('ALTER TABLE chado.organism_analysis 
   ADD CONSTRAINT organism_analysis_analysis_id_fk
   FOREIGN KEY (analysis_id) 
   REFERENCES chado.analysis(analysis_id)
   ON DELETE CASCADE')->execute();

I tried adding chado_set_active('chado') but that didn't change the result. I also tried using chado_query instead but no luck there either.

@bradfordcondon
Copy link
Contributor

shouldnt this be a core issue? If a schema defines foreign keys, tripal should hook into schema and add them>

@bradfordcondon
Copy link
Contributor

@almasaeed2010 just touching base on this.... my understanding is adding foreign keys does nothing when adding custom tables...

whats your opinion on this being a tripal core issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants