one-to-many

ForeignKey field with primary relationship

亡梦爱人 提交于 2019-12-12 03:23:48
问题 I have two tables in my database (django: models in my app) as follows: class Model1(models.Model): name = models.CharField() #etc.... class Model2(models.Model): link = models.ForeignKey(Model1) Each Model1 can have many instances of Model2 linked to it, but Model2 can only be linked to one Model1 - a basic one-to-many relationship. My problem is this: I need each Model1 to have a primary Model2 - that is, one of it's related Model2s needs to somehow be marked as "primary". These are my

one-to-many GQL query and putting results into a dictionary

喜欢而已 提交于 2019-12-12 03:16:09
问题 I have a google database called Main . class Main(db.Model): name = db.StringProperty() phone = db.StringProperty() There's another database Photo which references Main through a one-to-many relationship. class Photo(db.Model): main = db.ReferenceProperty(Main,collection_name='photos') photo1 = db.StringProperty() photo2 = db.StringProperty() I was wondering if anyone knows how to make a dictionary, based on the query of Main (example shown below): class Name(webapp.RequestHandler): def get

symfony2 deleteForm not working fine

别来无恙 提交于 2019-12-12 03:09:43
问题 I have 2 entities. I would like to delete row of Service. I tried: $em = $this->getDoctrine()->getEntityManager(); $service = $em->getRepository('AppBundle:Service')->find(1); $em->remove($service); $em->flush(); On this way it deleted all of the row, which containing this category id. Sry for my bad English. Let me explain you on the other way: BEFORE AFTER delete id 1 from service +----+------+ +----+------+-----+ +----+------+ +----+------+-----+ + id + ca_ + + id + se_ + ca_ + + id + ca_

How to declare a one-to-many in Fluent API so that it's not required?

核能气质少年 提交于 2019-12-12 02:59:00
问题 Suppose we have the two classes below. class Donkey { public Guid Id { get; set; } } class Monkey { public Guid Id { get; set; } public Donkey Donkey { get; set; } } I can configure the relation as follows. protected override void OnModelCreating(DbModelBuilder model) { base.OnModelCreating(model); model.HasDefaultSchema("dbo"); ... model.Entity<Monkey> .HasRequired(_ => _.Donkey) .WithMany() .Map(_ => _.MapKey("DonkeyId")); } I'd like to make it not-required, i.e. so that Donkey property can

CoreData predicate for one to many relationship

拈花ヽ惹草 提交于 2019-12-12 02:58:41
问题 I have two entity: A and B. Every element of A can have more elements of B (one to many). Now I have an item of A and I would to take, in this item, one item B (contained in A) that it has B.field = "myParameter". How can I generate the Predicate for this? 回答1: You may be looking for that (tested with MagicalRecord ): NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(field LIKE %@) AND (isLinkedToAObject == %@)", myFieldParameter, objectA]; With: ClassB has a property

jpa, eclips-link 2.5.1: OneToMany not working on columns not primary key

删除回忆录丶 提交于 2019-12-12 02:42:50
问题 I have these two entities: Anagrafica @Entity @Access(AccessType.FIELD) @Table(name = "S_MC_CC_USER") @SequenceGenerator(name = "SEQ_ID", sequenceName = "SEQ_ID", allocationSize = 1) public class Anagrafica implements Serializable{ private static final long serialVersionUID = 332466838544720886L; @EmbeddedId private AnagraficaId anagraficaId; @Column(name = "USER_ID") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ID") private Long userId; @OneToMany(cascade =

Hibernate updating one to many cascaded

社会主义新天地 提交于 2019-12-12 02:13:34
问题 I have two entities, which have one to many relationships. Purchase ----------------< lineCommand I have mapped those entities together, and everything works fine at least when I want to save or delete a purchase, except when I perform an update, only the parent (purchase will be update) and children won't be updated. Here the DDL for both Purchase and lineCommand: LineCommand: CREATE TABLE purchaseproduct ( idpurchaseproduct serial NOT NULL, idpurchase integer, idproduct integer, qty double

EntityFramework - One to many relationship

烈酒焚心 提交于 2019-12-12 01:39:48
问题 I have a one-to-many relationship between MapHeader and MapDetail tables therefore there can be multiple mapdetails for a single mapheader. In the database, table MapDetail has foreign key MapHeaderID which maps to the pk(MapHeaderId) in MapHeader table. I have defined it in EntityFramework Code-first as follows: public class MapHeader { public int MapHeaderID { get; set; } .... public virtual ICollection<MapDetail> mapDetails { get; set; } } public class MapDetail { public int MapDetailID {

Core Data: re-setting to-many relationship

纵然是瞬间 提交于 2019-12-12 01:18:04
问题 I have created model which you can see there: http://i.imagehost.org/0836/2009-11-08_14_37_41.png I want to store information about sound categories and some sample sounds for each category. Category has Name (NSString) and SoundsRelation (NSSet of NSData, which represents sounds). Here is the problem: For example I have some category which contains several sounds associated with it. Assume number of sounds is 3. So if I do NSLog(@"description: \n%@", category); I will see information about

Good one-to-many relation practice in MySQL

给你一囗甜甜゛ 提交于 2019-12-11 21:10:34
问题 I am developing the structure of the MySQL database and I've faced a small decisional problem about its structure. I have 2 tables: All messages published on the site. All comments published on the site. Every message can have more than one comment associated to it. What is a better way to make connection between a message and comments related to it? Have a field for comments that contains id of the related message. Have a field for messages that contains an array of ids of related comments