relationship

Laravel parent/children relationship on it's own model

五迷三道 提交于 2019-12-12 13:33:47
问题 I want to get all the vouchers that have at least one child, a voucher can have multiple voucher children, but any voucher can only have one parent. I set it up with the following models and calls, and the query it generates is as desired, until this part: 'vouchers'.'parent_id' = 'vouchers'.'id' Wanted functionality: $vouchers = Voucher::has('children')->get(); or $vouchers = Voucher::has('parent')->get(); Resulted Query select * from `vouchers` where `vouchers`.`deleted_at` is null and

Rails 3 - A model with a one to one relationship to itself - do I need belongs_to

廉价感情. 提交于 2019-12-12 11:44:16
问题 I have a model named Person. It has two properties - name and parent_person_id A person will always have a parent person. Should I be using belongs_to in the model? If so, what are the advantages of doing so. class Person < ActiveRecord::Base belongs_to :person end I've not tried this code out yet, it seems a bit wrong my normal mysql ways. I'm looking for opinions here more than anything, I'm quite new to the rails and want to make sure I'm doing things properly, doing things 'the Rails way'

Do I Have to Manually Set a Core Data Object's Inverse Relationship in Code on the iPhone

拟墨画扇 提交于 2019-12-12 11:15:05
问题 I am new to core data so please excuse me if I get some of the terms wrong. I have several objects in my xcdatamodel file. They are all inter connected with relationships and inverse relationships. If I connect two of these objects with the following code the inverse relationship is not set. [managedObj1 setValue: managedObj2 forKey:@"relatiohipName"]; I seem to have to manually set the inverse relationship myself with the following code [managedObj1 setValue: managedObj2 forKey:@

Integrity constraint violation: 1452 laravel

烈酒焚心 提交于 2019-12-12 11:12:22
问题 I have two tables in laravel created with the following migrations: User migration: public function up() { Schema::create('users', function($table){ $table->increments('id')->unsigned(); $table->string('email')->unique(); $table->string('password', 64); $table->string('first_name', 32); $table->string('last_name', 32); $table->string('remember_token', 100)->nullable(); }); } Occasion migration: public function up() { Schema::create('occasions', function($table){ $table->increments('id')-

Laravel Eloquent nested query

一笑奈何 提交于 2019-12-12 10:55:34
问题 I was working with Laravel and got stuck in a situation. I have following models: Category Product CategoryProduct CategoryProduct holds the information about which product belongs to which category (a product may belong to multiple categories). Now, when I want to load all products belonging to a particular category, I need to run query on Product and CategoryProduct which is where I'm stuck. I gave it the following try but was unsuccessful: $products = Product::where('status', '=', 'active'

Laravel “with” changes variable case to snake case

亡梦爱人 提交于 2019-12-12 10:38:23
问题 In my Laravel app, I have A model that defines a relationship like: public function vitalCategories() { return $this->belongsToMany( 'App\Models\Diagonals\VitalLabelCategory', 'vitalLabelCategoryMap', 'vitalLabelId', 'vitalLabelCategoryId'); } When I query a record like below, I expect the relation to be available with the variable name vitalCategories $vitalLabel = VitalLabel::where('label', 'confirmation')->with(['subscribers','vitalCategories','vitals'])->first(); return json_encode(

neo4j: one-directional / two-directional relationships?

六月ゝ 毕业季﹏ 提交于 2019-12-12 07:45:45
问题 So I looked into neo4j, and I may be using it in an upcoming project since its data model might fit my project very well. I looked through the docs but I still need an answer to this question: Can I set relationships to be one-directional? It seems that the neo4j people like movies so let's continue with that. If I have a graph like this: Actor A -> [:Acts in] -> Movie B then direction is obvious, because the nodes are different types. But I like horror movies so... Person A -> [:wants_to

Django M2M Through extra fields with multiple models

天大地大妈咪最大 提交于 2019-12-12 06:18:10
问题 I'm trying to figure out the best way to set up the following django model (genericised for security reasons). ThingA: User(M2M through "UserRelation") ThingB: User(M2M through "UserRelation") ThingC: User(M2M through "UserRelation") User: Login_name UserRelation: User (foreginkey) Thing (foreignkey) #is this generic to any of the above "things" Privilege I understand using "through" between two distinct models, but I'm not sure how to apply this to multiple models. Would I define a

Allow a OneToOne relationship to be optional in Symfony2

喜你入骨 提交于 2019-12-12 05:37:24
问题 I have a form responsible of creating and updating users. A user can (or not) have an address (OneToOne unidirectional relation from user). When I create a user, no problem. When I update a user, usually no problem. Problems come up when i update a user which already has an address and try to unset all the address fields. There is then a validation error. The wanted behavior would be to have the user->address relation set to null (and delete the previously set address on the DB). There is a

Doctrine: How to insert foreign key value

你说的曾经没有我的故事 提交于 2019-12-12 04:53:34
问题 I have two tables in my database: sliders and images . One slider can have many images, so the structure of tables is: --------- -------- | SLIDERS | | IMAGES | --------- -------- | id | | id | --------- -------- | title | | title | --------- -------- | sid | -------- SID is a foreign key associated to id in "SLIDERS" table. In entities I put bidirectional relationships OneToMany and ManyToOne , so fetched Slider result would contain Images Objects that belong to him, and Images would contain