foreign-keys

filter conditions from an association

眉间皱痕 提交于 2019-12-08 21:42:30
I have a search function, which works great for staff, so I can search by name. Now, I want filter staffs by staffgroup.groupname, but unfortunatelly i get this error: Column not found: 1054 Unknown column 'staffgroups.groupname' in 'where clause' I'm having the following tablelayout staffs (a person can belong to many groups) staff_staffgroups (HABTM-linking table) staffgroups (has a groupname) i used the conditions as follows: $tmpConditions['AND'][] = array('Staff.isActive =' => "1"); $tmpConditions['OR'][] = array('Staff.lastname LIKE' => "%$name%"); $tmpConditions['OR'][] = array(

Rails 4.2 foreign key

白昼怎懂夜的黑 提交于 2019-12-08 19:37:43
问题 Rails 4.2 newly supports adding and removing foreign keys (in migrations), like: # add a foreign key to `articles.author_id` referencing `authors.id` add_foreign_key :articles, :authors What I don't understand is: How is this add_foreign_key :articles, :authors different from this: add_column :articles, :author_id, :integer Thank you for any clarification! 回答1: The difference is that line: add_foreign_key :articles, :authors will actually generates this: ALTER TABLE "articles" ADD CONSTRAINT

In JPA, having a many-to-one as primary key throws referential integrity constraint violation

痞子三分冷 提交于 2019-12-08 19:04:27
I have defined the following entities: @Entity public class Child implements Serializable { @Id @ManyToOne(cascade = CascadeType.ALL) public Parent parent; @Id public int id; } @Entity public class Parent { @Id public int id; } When I try to persist a Child with the following code: Parent p = new Parent(); p.id = 1; Child c1 = new Child(); c1.id = 1; c1.parent = p; em.persist(c1); Hibernate throws a 'Referential integrity constraint violation' error: Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK3E104FC802AAC0A: PUBLIC.CHILD FOREIGN KEY(PARENT_ID)

Default value for foreign key in Django migrations.AddField

ぃ、小莉子 提交于 2019-12-08 16:39:31
问题 Using migrations, I need to add a new field (a foreign key) to a model. I know it can be done with: migrations.AddField( model_name='MyModel', name='state', field=models.ForeignKey(null=True, related_name='mymodel_state', to='msqa_common.MyModelState'), ), However, I don't want my field to be nullable. Instead, I want to use a default value for it, corresponding to the id of MyModelState whose name is "available" (id value might change in different machines). This "available" value of table

MySQL Foreign Key Constraint - Integer Column

南楼画角 提交于 2019-12-08 16:25:22
问题 I have an integer column which I would like to add a foreign key constraint to. Only problem is if that column does not have/need a value, by default MySQL puts in a '0' value. This obviously breaks the foreign key constraint as there is no record in the primary table with a PK of 0. How can I overcome this problem? 回答1: You may want to set your foreign key to accept NULL values, and use a NULL instead of a 0 value. Conceptually, NULL means a missing unknown value . If your row does "not have

How can I set user full name in foreignkey field with User Model using on_delete attribute?

纵饮孤独 提交于 2019-12-08 15:58:31
问题 I have a model in django that have foreignkey with User model. class News(models.Model): user = models.ForeignKey(AUTH_USER_MODEL, on_delete=models.SET(???)) message - models.TextField() So When any user account delete from database then in News table entries also deleted according to user. So I want that When any user account deleted then I need to set his/her full name in user field using 'on_delete=models.SET(???)' Example: If I have user that first_name = 'Neeraj' and last_name='Kumar'

Invalid Operation Exception MVC C#

不想你离开。 提交于 2019-12-08 15:19:00
问题 I am very new to c# and MVC. I am trying to create a web application to make bookings for an Opticians practice. I have created my database using Code-First Entity Framework. On the create booking page I have a drop down where an Optician can be selected. When I created the create page using CRUD, the drop down showed the UserId, however I am trying to change that to a concat(FullName) of the Application Users(Optician) FirstName and LastName. Booking model: public class Booking {

Does Oracle automatically create a secondary index for FOREIGN KEY columns?

。_饼干妹妹 提交于 2019-12-08 14:37:54
问题 I'm currenly developing on Oracle. I have several tables for which I defined FOREIGN KEY constraints. I have already read this SQL Server-oriented and this MySQL-oriented questions but I could find none about Oracle. So the question is always the same: in order to optimize query performance, for those columns for which I create a FOREIGN KEY constraint, do I also have to create an explicit secondary index? Doesn't Oracle automatically create an index on FOREIGN KEYed columns to boost

What kind of relationship do these 2 tables require?

送分小仙女□ 提交于 2019-12-08 13:53:00
问题 I have 2 tables and was wondering what the best relationship between them was. I know there is a relationship between them but I get so confused with one to many, many to one, many to many, unidirectional, bidirectional, multidirectional etc. So this is the basic, displayed, structure: Traveler Table: +------------------------------------------+ | Name | Family Name | National ID No. | +------------------------------------------+ | Dianne | Herbert | 579643 | | Francine | Jackson | 183432 | |

add fields to model from another one related with OneToOneField or ForeignKey relation

爷,独闯天下 提交于 2019-12-08 13:17:06
问题 i am new to django and i am using the 1.11 version i have several models some related with foreign keys and some with oneToOne relation. for instance the user and profile models, i would like to add in the profile form fields from the user form how? For the oneToOne, I have the an admin model with a oneToOne field related to the user model. but not just admin, i have several types of user (admin, writer, commetator, ...) each in a different model and when creating one type i also create its