foreign-key-relationship

Zend Framework 2 - Hydrator strategy for Doctrine relationship not working

◇◆丶佛笑我妖孽 提交于 2019-11-27 11:49:47
问题 As mentioned here I'm building a custom hydration strategy to handle my related objects in a select box in a form. My form looks like this: $builder = new AnnotationBuilder($entityManager); $form = $builder->createForm(new MyEntity()); $form->add(new MyFieldSet()); $hydrator = new ClassMethodsHydrator(); $hydrator->addStrategy('my_attribute', new MyHydrationStrategy()); $form->setHydrator($hydrator); $form->get('my_attribute')->setValueOptions( $entityManager->getRepository('SecEntity\Entity

Proper database model for a user feedback system (an interesting case)

*爱你&永不变心* 提交于 2019-11-27 09:36:51
I am developing an application using PHP and Yii Framework. I've been thinking about the most suitable database structure for the given functionality and here's what I've come up with. Yet I'm not 100% positive that's how it should be done so I've decided to ask the community. App Description: Registered users may participate in an event. Every event can have an unlimited number of users, called "participants of the event"). Once the event is over, every participant can leave a feedback about every other participant of the same event. Database structure: Since every event can have an unlimited

Multiple column foreign key contraints

青春壹個敷衍的年華 提交于 2019-11-27 09:31:19
I want to setup table constraints for the following scenario and I’m not sure how to do it or if it’s even possible in SQL Server 2005. I have three tables A,B,C. C is a child of B. B will have a optional foreign key(may be null) referencing A. For performance reasons I also want table C to have the same foreign key reference to table A. The constraint on table C should be that C must reference its parent (B) and also have the same foreign key reference to A as its parent. Anyone have any thoughts on how to do this? In general I do not see a specific reason to do this -- however, you did ask.

MySQL 5.5 foreign key constraint fails when foreign key exists

北慕城南 提交于 2019-11-27 09:17:49
Just installed MySQL 5.5 on mac os x 10.6 and am having a strange issue on many tables. Below is an example. Inserting a row fails with a foreign key constraint when it shouldn't. The foreign key it references does exist. Any ideas? mysql> show create table Language; +----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

SQL Sub queries in check constraint

廉价感情. 提交于 2019-11-27 09:00:33
Can I make SQL sub queries in Check constraint ? I've a post table with columns id, owner I've another table action with columns user_id, post_id Table user with columns id post_id -> post.id and user_id -> user.id also post.owner -> user.id Now I want to constraint post(post_id).id != user_id on table action How is that possible ? It is not supported to look beyond the current row in a CHECK constraint. http://www.postgresql.org/docs/9.1/interactive/sql-createtable.html says: A check constraint specified as a column constraint should reference that column's value only, while an expression

How to correctly add Foreign Key constraints to SQLite DB using SQLAlchemy [duplicate]

二次信任 提交于 2019-11-27 06:58:23
问题 This question already has an answer here: Sqlite / SQLAlchemy: how to enforce Foreign Keys? 7 answers I'm very new to SQLAlchemy and I'm trying to figure it out. Please have in mind the following test setup: class Nine(Base): __tablename__ = 'nine' __table_args__ = (sqlalchemy.sql.schema.UniqueConstraint('nine_b', name='uq_nine_b'), ) nine_a = sqlalchemy.Column(sqlalchemy.dialects.sqlite.INTEGER(), primary_key=True, autoincrement=False, nullable=False) nine_b = sqlalchemy.Column(sqlalchemy

Link in django admin to foreign key object

Deadly 提交于 2019-11-27 02:32:36
问题 I have a model A with a ForeignKey to a model B. In Django admin, how can I add a link in the admin page of model A next to the ForeignKey field which open the admin page of the model B ? 回答1: You can do the following: models.py (example): model B(models.Model): name = models.CharField(max_length=20) model A(models.Model): field1 = models.CharField(max_length=20) Bkey = models.ForeignKey(B) admin.py from django.core import urlresolvers class AAdmin(admin.ModelAdmin): list_display = ["field1",

Rails: Scaffold to automatically do one-to-many relationship

天大地大妈咪最大 提交于 2019-11-27 02:12:15
问题 Not sure if I'm reading this right, but it seems like Scaffold will not do a one-to-many relationship in its entirety. For instance, if I create messages with scaffold and then I want comments on those messages (one message -> many comments ), I have to go through and change everything. For instance, I have to change this in the comment 's new view <% form_for(@comment) do |f| %> to this <% form_for([@message, @comment]) do |f| %> and then change the Action to set up the @message var...

How to I show a list of ForeignKey reverse lookups in the DJango admin interface?

独自空忆成欢 提交于 2019-11-27 01:51:14
问题 I have a couple of models: class Customer(models.Model): customer_name = models.CharField(max_length=200) def __unicode__(self): return self.customer_name class Meta: ordering = ('customer_name',) class Unit(models.Model): unit_number = models.IntegerField() rentable = models.BooleanField() owner = models.ForeignKey(Customer, related_name='units', blank=True, null=True) def __unicode__(self): return str(self.unit_number) class Meta: ordering = ('unit_number',) I have the admin interface

Django foreign key relation in template

Deadly 提交于 2019-11-27 01:34:53
问题 i know you will say that this question is asked before many times but i havent solved it yet... models.py class Doc(UploadModel): doc_no = models.CharField(max_length=100, verbose_name = "No", blank=True) date_added = models.DateTimeField(verbose_name="Date", default=datetime.now, editable=False) class DocImage(models.Model): property = models.ForeignKey(Doc, related_name='images') image = FileBrowseField("Docs", max_length=200, directory="doc_img/%Y/%m/%d/%H/%M/%S/", extensions=[".jpg",".tif