This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

tyamz
tyamz

The problem that I'm having is, I cannot access certain information from the File Model such as File Path, File Name, and other information stored in the system_files table. I believe I have pinpointed where the issue is coming from, but I'm not sure how to fix it. Below I'll show some of the code.

1) File.php ~ File Model

<?php namespace Compuflex\Downloads\Models;
use Model;
use October\Rain\Database\Attach\File as FileBase;
/**
 * Model
 */
class File extends FileBase
{
    use \October\Rain\Database\Traits\Validation;
    /*
     * Validation
     */
    public $rules = [
    ];
    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;
    /**
     * @var string The database table used by the model.
     */
    public $table = 'compuflex_downloads_files';
    public $attachOne = [
            'file' => ['System\Models\File', 
                'key' => 'id']
    ];

    public $belongsToMany = [
            'user' => ['RainLab\User\Models\User']
    ];
}

In this file, you can see there are two relationships identified: $attachOne which attaches the file upload to the File Model as well as $belongsToMany which identifies the many-to-many relationship between users and files. (Many files can belong to Many users, or one user can have many files, but one file can also belong to many users). This is the file that sets up the file and user relation which you will see in the columns.yaml file. Just a side note, the only reason I set the 'key' =>'id' was to ensure that it was actually identifying the 'key' as 'id'.

2) Columns and Fields

I don't think the fields.yaml file is necessary, but just in case, you can find it here: fields.yaml

columns.yaml

columns:
    file_name:
        label: 'compuflex.downloads::lang.file.name'
        type: text
        searchable: true
        sortable: true
    full_name:
        label: 'compuflex.downloads::lang.file.username'
        type: text
        searchable: true
        sortable: true
        select: name
        relation: user
    email:
        label: 'compuflex.downloads::lang.file.email'
        type: text
        searchable: true
        sortable: true
        select: email
        relation: user
    file:
        label: 'compuflex.downloads::lang.file.path'
        type: text
        searchable: true
        sortable: true
        select: file_name
        relation: file

I'm more concerned with the columns.yaml file because that is what I am trying to fix is the back-end controller that displays the list of file information as well as information about the users they're "attached" to.

Here is a screenshot of what the view looks like: Screenshot of Back-end Controller As you can see, the "File" Tab is not displaying any information about the file, and it is supposed to be displaying the file_name column from the system_files table or at least from the File Model, but it displays nothing.

Now, what I find interesting, if I change the last entry in the columns.yaml file from the original to:

file:
    label: 'compuflex.downloads::lang.file.path'
    type: text
    searchable: true
    sortable: true

Then the following is output in the back-end controller:

After the changes...

Therefore, as you can see, the information IS there (allegedly), but I'm just not sure how to access it properly.

So, I have one last test that I did that I will show you, I knew that if the select: attribute in the columns.yaml file is set to a column name that's not in the system_files table it should produce an SQL Error of some sort (such as column name not found). And I was right... So, I set it to 'ile_name' instead of file_name, just for testing purposes.

Here is what the error message was:

SQLSTATE[HY000]: General error: 1 no such column: ile_name (SQL: select "compuflex_downloads_files".*, (select group_concat(name, ', ') 
from "users" inner join "file_user" on "users"."id" = "file_user"."user_id" where "file_user"."file_id" = 
"compuflex_downloads_files"."id") as "full_name", (select group_concat(email, ', ') from "users" inner join "file_user" on "users"."id" = 
"file_user"."user_id" where "file_user"."file_id" = "compuflex_downloads_files"."id") as "email", (select ile_name from "system_files" 
where "system_files"."attachment_id" = "compuflex_downloads_files"."id" and "system_files"."attachment_type" = ? and "field" = ?) as 
"file" from "compuflex_downloads_files" order by "file_name" desc)

Now, to pinpoint the issue more, I believe the issue might be coming from:

(select ile_name from "system_files" where "system_files"."attachment_id" = "compuflex_downloads_files"."id" and "system_files"."attachment_type" = ? and "field" = ?)

I think that those ? are causing this query to return NULL results from the table in turn causing there to be no output. I'm not 100% on this, it's just one possibility. The problem is, I don't know where OctoberCMS builds these queries or if there is any simple way to fix that without touching the actual code for October (for obvious reasons).

I am not the most experienced in editing .YAML and I don't know if I fully understand the list controller (or even partially understand it), but if anyone could please assist me, I'd really appreciate it. I've been stuck on this roadblock for days, and I feel once I move past it I'll have a much greater understanding of it all.

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.