many-to-many

NOT IN query with Doctrine QueryBuilder in a Many to Many relation

旧巷老猫 提交于 2019-12-23 12:37:52
问题 In my Symfony2 project, I have two entities "contact" and "settings", with a many to many relationship : /** * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Settings", cascade={"persist"}) * @ORM\JoinColumn(nullable=true) */ private $settings; Entity settings have a property "parametre", which is a simple string. Now I want to get all the contacts that DON'T have any settings which "parametre" is "THEMES". I can do that in SQL with a query like : SELECT DISTINCT(c.id) FROM contact c WHERE c

ManyToMany assoicate delete join table entry

烂漫一生 提交于 2019-12-23 12:26:37
问题 I use these two entities to create a new user and groups it associates: @Entity @Table(name="usertable") @SuppressWarnings("serial") @Searchable public class User implements Serializable { @GeneratedValue(generator="userIdSeq") @SequenceGenerator(name="userIdSeq", sequenceName="usertable_id_seq") @SearchableId @Id int id; @SearchableProperty String userId; // 'Unique identifier. It is formed using this fashion: ''prefix:identifier'' String userName; // Name used to log in the application.

Postgresql 9.3 - array_agg challenge

左心房为你撑大大i 提交于 2019-12-23 10:41:48
问题 I'm trying to understand the array_agg function in Postgresql 9.3. I've put together a fun example for everyone who may be interested in participating. Any fan of American films from the 1980's may be familiar with the "brat pack" who appeared in many hit films together. Using the information about the brat pack films on wikipedia, I've created tables that when joined together, can tell us who worked with each other -- if we have the right query! /* See: http://en.wikipedia.org/wiki/Brat_Pack

Duplicate entry for key 'PRIMARY' in JPA/Hibernate

旧巷老猫 提交于 2019-12-23 10:06:00
问题 I have a many-to-many relation in a mysql database ( Module - <Module_has_Subject> - Subject ). Entites were generated by Eclipse, I added the method add in both classes. I use JBoss AS7/Hibernate. When I call the persist method in EJB, I get org.hibernate.exception.ConstraintViolationException: Duplicate entry '3' for key 'PRIMARY' I know it must be a trivial mistake, but I just don't see it. I went through most related problems here on StackOverflow and RoseIndia (I added cascade ,

Rails 3 Factory Girl + Many to Many Relationships

不羁岁月 提交于 2019-12-23 09:34:06
问题 There aren't currently any up to date answers for this using Factory Girl 4.1 (that I could find) - how do you setup a many to many relationship inside of a factory? For instance I have Students and Classrooms which are in a many to many relationship using a join table, so far I had the following setup: factory :classroom do name "Foo Class" ... end factory :student do name "John Doe" ... end factory :student_with_classroom, :parent => :student do after(:build) {|student| student.classrooms <

Django: Many-to-many through a table with (only) compound key

一笑奈何 提交于 2019-12-23 09:31:23
问题 I have a legacy database with a table storing a many-to-many relationship, but without a single primary key column. Is there any way to convince Django to use it anyway? Schematically: Product 1<---->* Labeling *<---->1 Label The Labeling table uses (product_id,label_id) as a compound primary key, and I don't see any way to inform Django about this. (Just using through gives me Unknown column 'labeling.id' in 'field list' .) Do I need to fall back to custom SQL? Or am I missing something? 回答1

LINQ to SQL many to many int ID array criteria query

假装没事ソ 提交于 2019-12-23 06:06:10
问题 Ok this should be really simple, but I am doing my head in here and have read all the articles on this and tried a variety of things, but no luck. I have 3 tables in a classic many-to-many setup. ITEMS ItemID Description ITEMFEATURES ItemID FeatureID FEATURES FeatureID Description Now I have a search interface where you can select any number of Features (checkboxes). I get them all nicely as an int[] called SearchFeatures. I simply want to find the Items which have the Features that are

Laravel: selecting with conditions from Many-to-many relationships

两盒软妹~` 提交于 2019-12-23 05:58:31
问题 I have a many-to-many laravel relationship for posts and topics: Posts belongstoMany Topics Topics belongstoMany Posts I want to get posts with id > 10 from a certain topic The following code will get me all the posts from certain topic: $topic = Topic::where('id',$topic_id)->get()->first(); $posts= $topic->post; Now how to get posts with id > 10 ? Models: class Topic extends Eloquent{ public function post() { return $this->belongsToMany('post'); } } class Post extends Eloquent{ public

Many to Many Invalid Object name

杀马特。学长 韩版系。学妹 提交于 2019-12-23 05:51:46
问题 I have a Many-To-Many relationship created between Employee-Project in my code, but when I want to use its throws this exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'employee_project'. I tried, but I did not succeed finding the root cause of this exception. SO, please help me. Below are the POJOs for Employee and Project and also the code that throws this exception Employee pojo: @Entity @Table(name = "Employee") public class Employee { @Id @GeneratedValue

Symfony2, relation manyToMany in a Form

陌路散爱 提交于 2019-12-23 05:42:59
问题 I start learning sf2, pretty cool, for my problem I have two tables: Media /** * @ORM\ManyToMany(targetEntity="Test\SiteBundle\Entity\Website", inversedBy="medias") * @ORM\JoinTable(name="media_website") private $websites; and Website /** * @ORM\ManyToMany(targetEntity="Test\SiteBundle\Entity\Media", mappedBy="websites") private $medias; In my MediaType.php I have this: $builder ->add('title') ->add('website', 'entity', array( 'class' => 'TestSiteBundle:Website', 'property' => 'name', 'query