many-to-many

Fluent-NHibernate many-to-many cascade does not populate the link table

混江龙づ霸主 提交于 2019-12-05 02:09:29
OK, no matter how I define these mappings, my many-to-many mapping does not want to work with cascade insert. I have tried various combination of Cascade() with Reverse() and removing all unnecessary properties just to understand if they had anything to do with this not working, but no lock. It is really Simple stuff: I have a Message (like an email) which is sent from a user (I have called the entity BasicUser ) to a number of users (through property To ). User and Message in terms of recipients have a many-to-many relationship but FromUser has one-to-many. FromUser works fine and it is

Is @ManyToMany(mappedBy = … ) + @OrderColumn supported by the JPA?

我的梦境 提交于 2019-12-05 00:42:04
I have an entity mapped as following: @Entity @Table(name = "Groups") @IdClass(value = GroupId.class) public class Group implements Serializable { @Id @Column(name = "round_id") private Integer roundId; @Id @Column(name = "ordinal_nbr") private Integer ordinalNbr = 0; ... } It has a composite key (round_id, ordinal_nbr) to indicate the order of groups in a round. Now imagine a join table containing entities that link the ordered groups via a self reference (from Group to Group): CREATE TABLE GroupLinks ( parent_round_id INTEGER NOT NULL, parent_ordinal_nbr SMALLINT NOT NULL, child_round_id

How to lazy load a many-to-many collection in hibernate?

痞子三分冷 提交于 2019-12-05 00:32:37
I can lazy load one-to-many and many-to-one associations but I can't with the many-to-many associations. We have a city in wich we have merchants wich have adresses. Merchants can have multiple addresses and multiple merchants can have the same addresses. When we load a merchant with a get, Merchant merchant = (Merchant) hib_session.get(Merchant.class, id); System.out.println(merchant.getName()); it's ok, addresses aren't load until we iterate over them. But when we load a list of merchants, City city = (City) hib_session.get(City.class, city_name); for(Merchant merchant : city.getMerchants())

Many-to-many to DTOs using Automapper

廉价感情. 提交于 2019-12-05 00:01:03
问题 If I have a many-to-many relationship defined in EF: public class StudentImage { public int StudentId { get; set; } public int ImageId { get; set; } public int Order { get; set; } public virtual Student Student { get; set; } public virtual Image Image { get; set; } } public class Student { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<StudentImage> Images { get; set; } } public class Image { public int Id { get; set; } public string Filename { get;

No identifier/primary key specified for Entity (…) Every Entity must have and identifier/primary key

懵懂的女人 提交于 2019-12-04 23:30:33
I have Peticion entity but something is missing because appears the following error: No identifier/primary key specified for Entity (...) Every Entity must have and identifier/primary key This is the entity code: <?php namespace Project\UsuarioBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Peticion * * @ORM\Table(name="peticion") * @ORM\Entity */ class Peticion { /** * * @ORM\Id * @ORM\ManyToMany(targetEntity="Project\UsuarioBundle\Entity\Usuario", inversedBy="usuNick2") * @ORM\JoinTable(name="USUARIO", * joinColumns={@ORM\JoinColumn(name="USU_NICK_1", referencedColumnName="USU_NICK")},

hibernate @ManyToMany bidirectional eager fetching

可紊 提交于 2019-12-04 23:00:10
问题 I have a question which I think should be pretty common but I can't find an answer. I have 2 objects: Group and User. My classes look something like this: class Group { @ManyToMany(fetch = FetchType.EAGER) List<User> users; } class User { @ManyToMany(fetch = FetchType.EAGER) List<Group> groups; } Now, when I try to get a User from the database it brings all its groups and all groups bring all its users and so on. Finally, I'm getting a stackoverflow exception. How can I solve this issue and

Add an object by id in a ManyToMany relation in Django

筅森魡賤 提交于 2019-12-04 22:51:42
Django's ManyToMany field can be populated using my_field.add(my_instance) , but as I understand it only my_instance.id is actually needed to perform the corresponding SQL query. If I want to add an object by its id, I can use my_field.add(MyModel.objects.get(id=id)) , but this will generate two queries instead of one. How can I avoid this extra query? Although the documentation of the add method does not mention it, you can actually pass directly an id to it, like this: my_instance.add(id) Surely, this only works when the primary key is used as the identifier for the relation (the default

Compound/Composite primary/unique key with Django

笑着哭i 提交于 2019-12-04 22:40:11
How can you create models (and thus tables) with a compound (composite) primary/unique key using Django? Django does not support compound primary keys. You can create a single compound unique key with Meta.unique_together . if you want only unique mixed fields together use belowcode: class MyTable(models.Model): class Meta: unique_together = (('key1', 'key2'),) key1 = models.IntegerField() key2 = models.IntegerField() But if you want unique together and one of column be primary, set primary argument for model column, similar below code: class MyTable(models.Model): class Meta: unique_together

Django: how to aggregate / annotate over a many-to-many relationship?

瘦欲@ 提交于 2019-12-04 21:29:50
问题 I have a Person model and a Tag model, with a m2m between them. I need to extract the tag which is connected to the most records within a given Person queryset, together with the count. Is there an elegant, efficient way to extract this using the Django ORM? Better yet, is there a way to get the entire tag distribution through some annotation? How can one even pull all of the objects connected to a subset of objects connected via a m2m? Thanks! 回答1: This would give you the most frequent tag:

update pivot table in case of many to many relation laravel4

假装没事ソ 提交于 2019-12-04 20:08:43
问题 I have started working with Laravel4 recently. I am facing some problem while updating pivot table data, in case of many to many relation. The situation is: I have two table: Product , ProductType . The relation between them is Many to many . My Models are class Product extends Eloquent { protected $table = 'products'; protected $primaryKey = 'prd_id'; public function tags() { return $this->belongsToMany('Tag', 'prd_tags', 'prta_prd_id', 'prta_tag_id'); } } class Tag extends Eloquent {