relationship

Core data taking time to insert records with fetching entity & set as relationship

百般思念 提交于 2021-02-17 06:20:27
问题 I have 2 entities: Components & SurveyReadingWeb that have a one-to-many relationship. I have saved Components data in core data database; but while saving SurveyReadingWeb -- in a for loop -- I have to fetch Components data entity by passing component id and setting the surveyreadings isComponentexists relationship, like in the code below for 8000 records. This process is taking too much time, nearly 7 minutes. How can I reduce the time? for item in items { autoIncrementId = autoIncrementId

Unable to get and display grandchild relationship for dynamic menu in laravel 5.8

被刻印的时光 ゝ 提交于 2021-02-11 13:41:48
问题 I am creating dynamic multilevel menu in laravel, I am able to get parent and child relationship and display the menu but unable to get and display if relationship goes one more level down. Please assist. My Model: public function parent() { return $this->belongsTo('App\Menu', 'parent_id'); } public function children() { return $this->hasMany('App\Menu', 'parent_id'); } public function gchildren() { return $this->hasMany('App\Menu', 'parent_id'); } My Nav View: <ul class="navbar-nav">

how to pass a variable to service provider in Laravel?

不问归期 提交于 2021-02-09 09:23:40
问题 I want to generate a dynamic menu in a sidebar and share with all the views in Laravel 5.1. like: - Marks Module - Langosh Topic - Content 1 - Content 2 -Nitzsche Topic - Content 3 - Rolfson Module Although All this elements belong another entity called course which I can select in the Top menu (users can have more than 1 course). So every time that I access, Course, Module, Topic or Content they need to tell the sidebar menu which course is the father (or grandfather) of all of those kids to

how to pass a variable to service provider in Laravel?

限于喜欢 提交于 2021-02-09 09:15:07
问题 I want to generate a dynamic menu in a sidebar and share with all the views in Laravel 5.1. like: - Marks Module - Langosh Topic - Content 1 - Content 2 -Nitzsche Topic - Content 3 - Rolfson Module Although All this elements belong another entity called course which I can select in the Top menu (users can have more than 1 course). So every time that I access, Course, Module, Topic or Content they need to tell the sidebar menu which course is the father (or grandfather) of all of those kids to

How to determine programmatically MySQL relationship type (1:1, 1:n, n:m) between tables?

穿精又带淫゛_ 提交于 2021-02-08 03:57:14
问题 I'm trying to query a MySQL server to determine information about a database in order to scaffold some code. I've been quite successful using Java JDBC and INFORMATION_SCHEMA table for this but the problem is that I need to determine if a table relation is OneToOne , OneToMany or ManyToMany . I can't find a good way to achieve this and I would love if someone could help me a bit and if its possible with a solution that is not MySQL specific and solid so it could help others. I found this

Laravel sync Relation with optional parameters

那年仲夏 提交于 2021-02-08 03:39:26
问题 I use the sync function for syncing a belongsToMany Relation: $model->products()->sync($productIds); In the $productIds array there is flat array with some Id's - something like this: $productIds = [1,3,5,6]; What I want: The pivot table has also additional columns like "created_by" and "updated_by". But how can I add these fields to my array WITHOUT doing a foreach loop? Is there a shorter way to do this? I need an array like this: $productIds = [1 => [ 'created_by' => 1, 'updated_by' => 1 ]

Laravel 5.1 Eager Loading - belongsToMany with parameter

只谈情不闲聊 提交于 2021-02-07 10:58:23
问题 I have this relationship in my Model: public function modulesData($module) { return $this->belongsToMany($module) ->withTimestamps(); } What I want is to eagerload a dynamic relation of my model. But how can I do this? I use this code to eagerload my relation, but how can I add the parameter $module ? $model->with(['modulesData'])->get(); Thanks for reply. 回答1: Consider the following: Define the fallback function to your Model: public function __call($name, $arguments) { if (strpos($name,

SQLAlchemy declarative many-to-many self-join via Association object

我是研究僧i 提交于 2021-02-06 18:36:43
问题 I have a table Users and a table Friends which maps users to other users as each user can have many friends. This relation is obviously symmetric: if user A is a friend of user B then user B is also a friend of user A, I only store this relation once. The Friends table has additional fields besides the two User ID's so I have to use an association object. I am trying to define this relationship in declarative style in the Users class (which extends the declarative base), but I can't seem to

laravel eloquent relation one to many returns null

烂漫一生 提交于 2021-02-04 21:14:25
问题 The product data always return null when i get the incoming_goods data (belongsTo). Here is my Product Model: <?php namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Product extends Model { use SoftDeletes; protected $guarded = [ 'id', 'created_at', 'updated_at', 'deleted_at', ]; public function transaction_details() { return $this->hasMany('App\Transaction_detail'); } public function incoming_goods() { return $this->hasMany('App

SQL database relationships: unable to determine between manyToMany and oneToMany

Deadly 提交于 2021-01-29 18:34:48
问题 I have two database tables "Users" and "Transactions" where the "Transactions" table looks like below. The "Transactions" table has a record of each transaction between two accounts where the differentiator is "senderAccount" and "recipientAccount" columns. id | transactionId | senderAccount | recipientAccount | Amount | —--+---------------+---------------+------------------+--------+ 1 | ijiej33 | A | B | 100 | The relationship between "Users" and "Transactions" is one to many since every