• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: MySQL and Foreign Keys
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MySQL and Foreign Keys


  • Subject: Re: MySQL and Foreign Keys
  • From: Jacky Gagnon <email@hidden>
  • Date: Fri, 25 Mar 2005 14:28:57 -0500



This seems to be a common problem that is easily solved if you allow WebObjects manage foreign key constraints and not the DB. In other words, use the Mandatory/Optional settings in EOModeler's relationship inspector and do not use foreign key constraints in the database. Using foreign key constraints in the DB can make it impossible to implement some types of inheritance also.

I agree, its probably the easiest way, if you don't need the foreign key constraint in the DB.

But if your needs require it (ex: the constraint ON DELETE CASCADE for performance reason), the delegate databaseContextWillPerformAdaptorOperations is probably the way to go.

Example from http://www.wodeveloper.com/omniLists/eof/2001/May/msg00021.html :

<x-tad-bigger>
-----------------------------8<------------ cut here --------------------

public NSArray databaseContextWillPerformAdaptorOperations(EODatabaseContext aDatabaseContext, NSArray adaptorOperations, EOAdaptorChannel adaptorChannel) {

NSMutableArray someAdaptorOperations = null;
NSMutableArray insertOperations = new NSMutableArray();
NSMutableArray deleteOperations = new NSMutableArray();
NSMutableArray returnOperations = new
NSMutableArray(adaptorOperations);

Enumeration insertEnumerator = adaptorOperations.objectEnumerator();
while (insertEnumerator.hasMoreElements()) {
EOAdaptorOperation operation =
(EOAdaptorOperation)insertEnumerator.nextElement();
EOEntity entity = operation.entity();
String entityName = entity.name();
int adaptorOperator = operation.adaptorOperator();
if (entityName.equals ("someEntity")) {
if (adaptorOperator == EODatabaseOperation.AdaptorInsertOperator)
insertOperations.addObject(operation);
if (adaptorOperator == EODatabaseOperation.AdaptorDeleteOperator)
deleteOperations.addObject(operation);
}
}

if (insertOperations.count() > 0 || deleteOperations.count() > 0) {
someAdaptorOperations = new NSMutableArray(adaptorOperations);

someAdaptorOperations.removeObjectsInArray(insertOperations);

someAdaptorOperations.removeObjectsInArray(deleteOperations);
returnOperations = insertOperations;

returnOperations.addObjectsFromArray(someAdaptorOperations);
returnOperations.addObjectsFromArray(deleteOperations);
}

return returnOperations;
}
-- </x-tad-bigger>



Jacky


Regards, Kieran

On Mar 23, 2005, at 11:01 AM, Doug Andrews wrote:

Is there a way to get EOF to order database operations when using MySQL?
Basically, here is the problem:
Table A has a 'to one' relationship with table B.
I want to add a record to both tables within the same transaction, but if i cannot control the order of database operations, i will get a foreign key constraint error.

FrontBase has the "DEFERRABLE INITIALLY DEFERRED" option for your foreign keys that would solve this problem.
There does not seem to be an option like this for MySQL.
Does anyone know how to deal with this issue when using MySQL?


- Doug Andrews
- Baseview Products
- Ann Arbor, MI
- email@hidden

_______________________________________________
WebObjects-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/webobjects-dev

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >MySQL and Foreign Keys (From: Doug Andrews <email@hidden>)
 >Re: MySQL and Foreign Keys (From: Kieran Kelleher <email@hidden>)

  • Prev by Date: Re: MySQL and Foreign Keys
  • Next by Date: Re: Why WOBuilder only displays EOModel attributes and not java properties
  • Previous by thread: Re: MySQL and Foreign Keys
  • Next by thread: how to get fresh data from backend?
  • Index(es):
    • Date
    • Thread