Laravel / Eloquent - Many to many pivot model with morphToMany relation - laravel

I have a manyToMany relationship set up and have modelled the pivot table also. Also, in the pivot model I have a morphToMany relationship set up.
Here is a diagrammatic representation of the setup.
The trouble I am having is that I can't pull in the joins attribute on the pivot model.
I have this code in my Dimension model;
return $this->belongsToMany('Datasource', 'dimension_datasource')->withPivot('joins');
But I get this error: Unknown column dimension_datasource.joins
I have tried setting up an accessor on the pivot model but it appears that it is being ignored as I get the same error.
Thanks,
Geoff

This is working now. I'm distressed to admit I am not 100% sure why, but I'm fairly certain it was to do with the character encoding of backslashes in the fully qualified class names in the joinable_type column of the joinables table. So, if you are having the same issue, try looking there (there are indications elsewhere on the internet that Laravel should be escaping those backslashes and also vague suggestion of server settings being relevant).
Sorry I can't be more specific!!

Related

Laravel relationship on a column that is an array

I am rather stuck (or not stuck, as I could go and solve this simply with foreach) with a problem I am facing.
I have database where I have a model that should have a relation to another one. No problem here. However, that relation is defined in a column that is an array. I sadly cant change that. Is there any way to still get the corresponding relation of hasMany etc?
Or is my only choice to get all entries of my model and then go over foreach?
Thanks in advance.

What does a colon followed by two column names after a relationship do when eager loading?

When looking for a fix for an issue I had dealing with Datatables, I found this interesting syntax but I cannot find anything on the Laravel documentation to help me understand what's going on but I'd like to learn its useability.
This is the code snippet:
return $model->select('sessions.*')
->with('employee:id,name');
It’s mentioned in the docs: https://laravel.com/docs/8.x/eloquent-relationships#eager-loading-specific-columns
You may not always need every column from the relationships you are retrieving. For this reason, Eloquent allows you to specify which columns of the relationship you would like to retrieve:
$books = Book::with('author:id,name')->get();

Oracle Data Modeller: Recursive One to many relationship

I am having trouble understanding how to create recursive one to many relationships in a logical model built by Oracle data modeller.
The relational relationship should be similar to this i.e Manager ID is a FK for the same table
I have my logical model set up as so:
However, when I engineer to relational this is my result.
This behaves fine if I am creating a relationship for two different tables, Manager and Employee. PK on source table appears as FK target table.
How can I set up my logical model to create one FK called managerID with a one-to-many relationship on the same table?
Thanks.
i faced it initially.I think you have done the steps correctly, its just the notation is not showing the linkage as i see the linkage in the diagram but the attribute is not visible in the diagram.Try switching from Barker notation.
go to View>>Logical Diagram Notation >>Information Engineering Notation
let me know if this resolved your mystery :)

Laravel 5.4 models relationship

I'm struggling to find a way to output all NORMS (last table on the right) where JURISDICTIONS (last table on the left) is equal to a parameter given by a select (i did this using eloquent hasManyThrough, and i did output all norms related to that specific Jurisdiction) and where, and here comes the problem, these Norms belongs to a specific category also passes by a select (the smallest table in the image, DETAILREDACS).
NORMS and DETAILSREDACS are ManyToMany related.
Here are the two main attempts:
How can i achieve this? I've tried joining tables, but i'm probably doing something wrong.
I'm using Laravel 5.4.
Thanks!!!

Laravel: What are models?

I'm confused as to what models are and do in Laravel. I've tried to find some explanations but couldn't find any.
Can someone briefly explain what models are, when I would use them, and why I should use them?
More so, what are fillable and guarded attributes? I don't find they're very well explained in the docs.
For example, I have a table in my database, called login_log, that contains all login attempts. Would I create a model for this? Why?
Model is represented by M when you talk about MVC which stands for Model, View and Controller.
In Laravel Model is simply your database table object. This allows you to interact with your database tables as if they are PHP objects or classes.
Fillable property is used to tell laravel to allow mass assignment for the listed fields
while Guard property is the opposite of fillable
Laravel documentation is the best documentation so far.
See this Links to Understand well : Mass Assignment in Eloquent ORM for Laravel 4.2
Suggestions:
If you are newbie in Laravel, as I am Android Application Developer
i've find solution and understood too.
You have to learn documentation before putting question.
As MVC stands for Model View Controller, Model Deals with Database for example controller ask to Model to give me the first names of Students from the student table an d then controller pass it to the view.

Resources