Giter Club home page Giter Club logo

Comments (12)

fico7489 avatar fico7489 commented on July 29, 2024 1

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.

fico7489 avatar fico7489 commented on July 29, 2024 1

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.

fico7489 avatar fico7489 commented on July 29, 2024 1

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.

fico7489 avatar fico7489 commented on July 29, 2024 1

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.

delmicio avatar delmicio commented on July 29, 2024

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.

fico7489 avatar fico7489 commented on July 29, 2024

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.

delmicio avatar delmicio commented on July 29, 2024

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.

delmicio avatar delmicio commented on July 29, 2024

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.

fico7489 avatar fico7489 commented on July 29, 2024

bugfix is pushed to all branches, can you try now ?

from laravel-eloquent-join.

delmicio avatar delmicio commented on July 29, 2024

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.

delmicio avatar delmicio commented on July 29, 2024

Hey @fico7489 this issue is still present, you should not close it.
Were you able to reproduce it?

from laravel-eloquent-join.

fico7489 avatar fico7489 commented on July 29, 2024

It is fixed in 2.2.4 version I tested with your database...

from laravel-eloquent-join.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.