one-to-many

Doctrine cascade on OneToMany does not set the parent object?

…衆ロ難τιáo~ 提交于 2019-12-24 23:45:04
问题 I have a User objects which has many Journal entries. The user class contains a $userJournals property and the required add/remove functions, as below: class User{ .... /** * @var \Doctrine\Common\Collections\ArrayCollection * * @ORM\OneToMany(targetEntity="models\UserJournal", mappedBy="user", cascade={"persist"}) */ protected $userJournals; .... public function addUserJournal(\models\UserJournal $userJournal) { $this->userJournals->add($userJournal); return $this; } } The UserJournal class

How to save to Database with associations in rails protecting mass assignment

社会主义新天地 提交于 2019-12-24 22:41:50
问题 After trying for few hours I can not save to the database. The context is this: I have two types of users, one for that I only need very basic information [Username, email, password] and another kind of user for who I need a lot of information [age, gender, city and so on] I did not use STI becouse of the vast quantity of Null values there would be in the table. So I created this three modes in which a user has a profile (profiles table) or not depending of its type [1 or 2], and a field of

Grails v3.3.9 GORM defect - one to many with mappedBy, updates can be made to fail

☆樱花仙子☆ 提交于 2019-12-24 19:29:55
问题 Grails v3.3.9 - impacts live/dev and integration test My scenario is that I had an integration test that kept failing when building a manually created record and one found from DB, but works if you link two manually created records in the test. I have been trying a thousand tweaks and make sure GORM was doing what it said in docs. I've pared my code right back and built something simpler that looks structurally like my real stuff but is based on the Airport/Flights model in the GORM user

EF5 update disconnected graph (n-tier) one-to-many

旧街凉风 提交于 2019-12-24 15:52:31
问题 Problem: insert / update entity related to a parent with a one-to-many relationship in a disconnected graph scenario . UPDATE I found that the problem is just with new UserProfile I add to Brewery, the first insert is done successfully (= EF sees the relationship and creates the correct insert statement) exec sp_executesql N'insert [dbo].[BreweryUserProfiles]([BreweryId], [UserId]) values (@0, @1) ',N'@0 int,@1 int',@0=12,@1=3 No way till now to have the update working. --- The parent entity

@ManyToOne and @OneToOne relations with @EmbeddedId

半腔热情 提交于 2019-12-24 08:36:07
问题 I am trying to change the id of my database entities from a single long to a composite id consisting of two long's which are encapsulated in my ID.class shown below. What annotations would you use for ManyToOne and OneToMany relations? Did I made a mistake with my annotations, especially with @JoinColumns, @Embeddable and @EmbeddedId. My problem is that relations are stored with null; My ID class consist of an autogenerated long (pid) and a manually set secondary long (sid). This is the ID

OneToMany & ManyToOne mapping Spring Boot / Hibernate

邮差的信 提交于 2019-12-24 08:28:35
问题 I have two tables with foreign key relations. I've tried searching on how to do it and it always leads to OneToMany & ManyToOne mapping. I have these two tables. user_role user I'm trying to display all the users and show their position by getting the value of the position column to the user_role table. These are my classes User.java @Entity @Table(name="user") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; .......... private UserRole userRole;

OneToMany & ManyToOne mapping Spring Boot / Hibernate

霸气de小男生 提交于 2019-12-24 08:28:19
问题 I have two tables with foreign key relations. I've tried searching on how to do it and it always leads to OneToMany & ManyToOne mapping. I have these two tables. user_role user I'm trying to display all the users and show their position by getting the value of the position column to the user_role table. These are my classes User.java @Entity @Table(name="user") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; .......... private UserRole userRole;

Hibernate one to many mapping error - mappedBy reference an unknown target entity property error

谁说胖子不能爱 提交于 2019-12-24 06:35:56
问题 I am trying to test one to many mapping by creating tables from domain objects but I see the error mappedBy reference an unknown target entity property . Could some one take a look please? Thanks Employee.java import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax

Multiple (oneToMany) Entities form generation with symfony2 and file upload

最后都变了- 提交于 2019-12-24 05:03:52
问题 I'm on a problem related to a Symfony2 application which i'm building. The problem concerns an article (News) linked to one or many pictures (Illustration). It seems pretty simple. But i'm stacking on the controller which should persist the News, the Illustration and uploading the picture file. My News form type: namespace Fcbg\NewsBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class NewsType extends AbstractType { public function

Multi-page Multi-Model Form in Rails

一个人想着一个人 提交于 2019-12-24 00:48:48
问题 I'm trying to create a multi-page form that uses multiple models. I have an applicant and this applicant has more than one address (one to many relationship). I would like the first page to contain information about the applicant, and then the page after that to have the form for the address(es) This is what I have at the moment: applicant.rb has_many :addresses, :dependent => :destroy accepts_nested_attributes_for :addresses address.rb belongs_to :applicant applicants_controller.rb: def new