many-to-many

Laravel 4.1: proper way to retrieve all morphedBy relations?

时间秒杀一切 提交于 2019-12-03 08:16:36
Just migrated to 4.1 to take advantage of this powerful feature. everything seems to work correctly when retrieving individual 'morphedByXxxx' relations, however when trying to retrieve all models that a particular tag belongs to -- i get an error or no results. $tag = Tag::find(45); //Tag model name = 'awesome' //returns an Illuminate\Database\Eloquent\Collection of zero length $tag->taggable; //returns Illuminate\Database\Eloquent\Relations\MorphToMany Builder class $tag->taggable(); //returns a populated Collection of Video models $tag->videos()->get(); //returns a populated Collection of

Hibernate: mapping many-to-many to Map

一笑奈何 提交于 2019-12-03 08:07:05
I am developing an application which deals with two following entities: Products (let's name it as X, Y, Z) and Materials (a, b, c, ...). It's known that every product has a recipe which indicates what materials are required for making this product. For example, to produce one X we need 2 a, 6 c and 4 d (X = 2a + 6c + 4d). That's how it reflects in a database tables: Products id INT name VARCHAR ... Materials id INT name VARCHAR ... Recipes product_id INT material_id INT count INT The "count" field in the third table is a coefficient for materials of the same kind (2, 6, 4 from the example).

Need help with many-to-many relationships in core data for iPhone

邮差的信 提交于 2019-12-03 07:40:39
I have come to a roadblock in my current project. I basically have an app that is much like the Core Data Recipe app... Here is the basic structure I have in my .xcdatamodel Entity: Restaurant String: name Category: category <---- to-many relationship Entity: Category String: name Restaurant: restaurant <---- to-many relationship So basically, a Restaurant can have multiple categories... And there are a const number of predefined Categories.. For example: Restaurant: Name: Chili’s Categories: Take Out , Family Dining “Take Out” and “Family Dining” are 2 of 10 different possible Restaurant

Foreign key contraints in many-to-many relationships

最后都变了- 提交于 2019-12-03 07:36:30
问题 Context We're building a blog for an intro. to databases course project. In our blog, we want to be able to set Labels on Posts . The Labels can't exist by themselves, they only do so if they are related to a Posts . This way, Labels that are not used by any Posts shouldn't stay in the database. More than one Label can belong to a single Post , and more than a single Post can use a Label . We are using both SQLite3 (locally/testing) and PostgreSQL (deployment). Implementation Here is the SQL

Fluent NHibernate Self Referencing Many To Many

允我心安 提交于 2019-12-03 07:33:30
I have an entity called Books that can have a list of more books called RelatedBooks. The abbreviated Book entity looks something likes this: public class Book { public virtual long Id { get; private set; } public virtual IList<Book> RelatedBooks { get; set; } } Here is what the mapping looks like for this relationship HasManyToMany(x => x.RelatedBooks) .ParentKeyColumn("BookId") .ChildKeyColumn("RelatedBookId") .Table("RelatedBooks") .Cascade.SaveUpdate(); Here is a sample of the data that is then generated in the RelatedBooks table: BookId RelatedBookId 1 2 1 3 The problem happens when I Try

Laravel 4: Working with relationships in seeds

安稳与你 提交于 2019-12-03 07:21:04
问题 Is there an easy way to manage many-to-many relationships in the new seeds feature of L4? One way would be to make a seed for the pivot table, but I would be a lot of work. Any thoughts on a good workflow for this sort of thing? 回答1: In the latest version of Laravel 4 you define the order that all the seeder scripts are run in the "run" method of the DatabaseSeeder class. public function run() { DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $this->call('PrimaryTableOneSeeder'); $this->command-

Symfony2 Doctrine2 Many-To-Many relation with two Owning Sides and Doctrine cmd line tools

不羁的心 提交于 2019-12-03 07:16:58
问题 In my Symdony2 project I've two related entities: Service and ServiceGroup. This should be many-to-many relationship, because each group can have many services, and each service can belongs to many groups. Moreover, I need a user interface to manage services and groups. So, when editing a Service, user should be able to choose to which groups it belongs. Analogously, when editing a ServiceGroup user should be able to choose which services belongs to this group. I've already achieved this by

Spring and/or Hibernate: Saving many-to-many relations from one side after form submission

末鹿安然 提交于 2019-12-03 07:07:42
问题 The context I have a simple association between two entities - Category and Email (NtoM). I'm trying to create web interface for browsing and managing them. I have a simple e-mail subscription edit form with list of checkboxes that represents categories, to which given e-mail belongs (I registered property editor for Set<Category> type). The problem Form displaying works well, including marking currently assigned categories (for existing e-mails). But no changes are saved to EmailsCategories

How to access both directions of ManyToManyField in Django Admin?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 06:59:39
问题 The Django admin filter_horizontal setting gives a nice widget for editing a many-to-many relation. But it's a special setting that wants a list of fields, so it's only available on the (admin for the) model which defines the ManyToManyField ; how can I get the same widget on the (admin for the) other model, reading the relationship backwards? My models look like this (feel free to ignore the User / UserProfile complication; it's the real use case though): class Site(models.Model): pass class

How to properly index a many-many association table?

左心房为你撑大大i 提交于 2019-12-03 06:59:38
问题 In a typical many-many arrangement like this... Movies Actors Movies_Actors ------ ------ ------------- movie_ID actor_ID FK_movie_ID title name FK_actor_ID ... how should the association table ( 'Movies_Actors' ) be indexed for optimal read speed? I usually see this done only with the composite primary key in the association table, like so: CREATE TABLE Movies_Actors ( FK_movie_ID INTEGER, FK_actor_ID INTEGER, PRIMARY KEY (FK_movie_ID, FK_actor_ID) ) However, this seems like the index will