Comments (12)
I think that your ZoomMeeting model is not correct.
protected $primaryKey should be 'id', 'zoom_meeting_id' or something like that, not 'live_class_id'.
live_class_id is foreign key not primary key,
from laravel-eloquent-join.
you are using live_class_id as primary and foreign key in zoom_meetings table and this can not be correct regardless of this package. You probably need this schema:
CREATE TABLE `zoom_meetings` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`live_class_id` int(10) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
);
CREATE TABLE `live_classes` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
);
id is primary key for zoom_meetings
id is primary key for live_classes
live_class_id is foreign key for zoom_meetings <-> live_classes relation
from laravel-eloquent-join.
I never saw that someone is using the same field as primary and foreign key, but I guess it is possible. This is a some kind of an edge case, but yes, it's maybe a bug, I'll check it in detail tomorrow and fix it if it's a bug.
from laravel-eloquent-join.
Thanks for bug report. I fixed and tested with your database and models and now everything seems fine. Most of the people use 'id' for primary key and that is the reason why nobody reported this bug...
from laravel-eloquent-join.
We are using 'live_class_id' on ZoomMeeting as primary key and as foreign key too, this is an allowed behaviour on laravel.
from laravel-eloquent-join.
yes of course it is allowed, but strange. I can check what is the problem if you send me your migrations or db schema for live_classes and live_classes tables...
from laravel-eloquent-join.
sure ...
CREATE TABLE `zoom_meetings` (
`live_class_id` int(10) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`live_class_id`),
CONSTRAINT `FK_zoom_meeting_id__live_class_id` FOREIGN KEY (`live_class_id`) REFERENCES `live_classes` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
CREATE TABLE `live_classes` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `live_classes_created_at_index` (`created_at`),
KEY `live_classes_updated_at_index` (`updated_at`)
) ENGINE=InnoDB AUTO_INCREMENT=116028 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Thank you for helping ❤️
from laravel-eloquent-join.
But I don't need an AUTO_INCREMENT id column. Again, the schema is fine.
https://stackoverflow.com/questions/17636106/can-a-foreign-key-act-as-a-primary-key
>>> App\Models\LiveClass::first()->getKeyName()
=> "id"
>>> App\Models\ZoomMeeting::first()->getKeyName()
=> "live_class_id"
Maybe you can use on your package a getRelationships
method as here:
https://laracasts.com/discuss/channels/eloquent/get-all-model-relationships
from laravel-eloquent-join.
bugfix is pushed to all branches, can you try now ?
from laravel-eloquent-join.
I've updated and re-tried but got the same error.
root@abb3d5449ddc:/var/www# artisan tinker
Psy Shell v0.8.17 (PHP 7.1.12-3+ubuntu16.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> App\Models\ZoomMeeting::whereJoin('live_class.id', '>', 0)->count()
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'live_classes.live_class_id' in 'on clause' (SQL: select count(*) as aggregate from `zoom_meetings` left join `live_classes` on `live_classes`.`live_class_id` = `zoom_meetings`.`live_class_id` where `live_classes`.`id` > 0 group by `zoom_meetings`.`live_class_id`)'
>>>
root@abb3d5449ddc:/var/www# composer show -- fico7489/laravel-eloquent-join
name : fico7489/laravel-eloquent-join
descrip. : This package introduces the join capability for sorting and filtering on eloquent relations.
keywords : laravel, laravel eloquent join, laravel join relation, laravel join relations, laravel sort join, laravel where join
versions : * 2.1.3
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source : [git] https://github.com/fico7489/laravel-eloquent-join.git adc6c57016057b90dad1ed326bd68a3fc5c352f4
dist : [zip] https://api.github.com/repos/fico7489/laravel-eloquent-join/zipball/adc6c57016057b90dad1ed326bd68a3fc5c352f4 adc6c57016057b90dad1ed326bd68a3fc5c352f4
names : fico7489/laravel-eloquent-join
autoload
psr-4
Fico7489\Laravel\EloquentJoin\ => src
requires
illuminate/database 5.5.*
requires (dev)
orchestra/testbench ~3.5.0
from laravel-eloquent-join.
Hey @fico7489 this issue is still present, you should not close it.
Were you able to reproduce it?
from laravel-eloquent-join.
It is fixed in 2.2.4 version I tested with your database...
from laravel-eloquent-join.
Related Issues (20)
- wrong attribute value HOT 3
- Join multiple relationships by calling the joinRelations method once HOT 4
- Problem when joining the same table multiple times HOT 3
- Class `DB` not found HOT 2
- LoadCount not support HOT 1
- supports laravel 8? HOT 1
- OrderByJoin for BelongsTo relationships breaks in laravel 5.5 HOT 1
- Optional Group by
- Blockchain/E-currency software
- Count without first calling ->get() always returns 1
- Laravel 9, all test fail, not sure how to fix those errors but i have updated the dependencies to illuminati 9 and run your tests this is the result.
- Laravel 9 HOT 5
- Support laravel 10 HOT 1
- Aggregate parameters are not escaped HOT 2
- Syntax error or access violation: 1055 '...' isn't in GROUP BY HOT 1
- Error when applying sort by join on MSSQL DB HOT 3
- Column not found: 1054 Unknown column 'sort' in 'order clause'
- Question: Why is this not the default in Eloquent? HOT 2
- Question: Eager loading HOT 5
- Laravel 7.x - Cannot install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-eloquent-join.