Sails: Associations and foreign keys

Created on 21 Feb 2016  Â·  10Comments  Â·  Source: balderdashy/sails

Hi,
I tried to create an association as described in this example [http://sailsjs.org/documentation/concepts/models-and-orm/associations/one-to-many], but I noticed that there is no foreign key between pet and user, and that can create a data integrity problem. and when I tried to add the foreign key constraint manually, I noticed that 'pet.owner' is an int(11) while 'user.id' is an int(10) unsigned, so the foreign key constraint can't be created.
What do you think about this?

All 10 comments

I have the same problem with a many-to-many relationship. The primary keys of all my tables get created as INT(10), and the fields in the join table are INT(11). I'd welcome a foreign key, but for now i'd be super glad to just have _any_ index on the columns automatically.

ccoenen,

you can have what you want using this example : [http://sailsjs.org/documentation/concepts/models-and-orm/associations/through-associations]. You will have a table named petuser with an auto_increment id

The many-to-many without "through" does pretty much the same thing, it creates a join table (but it names it automatically) and it also has a sperate id field with auto_increment. What I couldn't gather (and currently can't test) is, if the through alone will set up keys/index for the two join columns.

@ilo2008,@ccoenen: Hello, I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message and simply close the issue if possible. On the other hand, if you are still waiting on a patch, please post a comment to keep the thread alive (with any new information you can provide).

If no further activity occurs on this thread within the next 3 days, the issue will automatically be closed.

Thanks so much for your help!

The original issue is still open, and i'd consider a foreign key at least an enhancement. Some people might even consider the lack of the FK a bug.

I confirm

On 25 March 2016 at 23:43, Claudius Coenen [email protected] wrote:

The original issue is still open, and i'd consider a foreign key at least
an enhancement. Some people might even consider the lack of the FK a bug.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/balderdashy/sails-mysql/issues/285#issuecomment-201590755

_الشعر أنا، وأنا الشعر_

@ccoenen @ilo2008 would you like to put together a PR for the auto migrations stuff on this? For most cases in the SQL adapters it's recommended to manually create migrations and the database structure using something like sails-migrations.

I agree with particlebanana. I did a fast test wiith examples from sails-migration page and I realize that the generated model needs to be fixed for associations.

@ilo2008,@ccoenen,@sailsbot,@particlebanana,@hollowsaibot,@scippio: Hello, I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message and simply close the issue if possible. On the other hand, if you are still waiting on a patch, please post a comment to keep the thread alive (with any new information you can provide).

If no further activity occurs on this thread within the next 3 days, the issue will automatically be closed.

Thanks so much for your help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alirezamohammadi picture Alirezamohammadi  Â·  4Comments

Salakar picture Salakar  Â·  4Comments

randallmeeker picture randallmeeker  Â·  4Comments

mahfuzur picture mahfuzur  Â·  3Comments

victory-deployment picture victory-deployment  Â·  4Comments