Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use \AlgoWeb\PODataLaravel\Models\MetadataTrait; #175

Open
yuri1994 opened this issue Jul 25, 2018 · 11 comments
Open

how to use \AlgoWeb\PODataLaravel\Models\MetadataTrait; #175

yuri1994 opened this issue Jul 25, 2018 · 11 comments

Comments

@yuri1994
Copy link

i try to put \AlgoWeb\PODataLaravel\Models\MetadataTrait in my model class but after call the odata it return me

404 Resource not found for the segment 'userlocation'.

The model class is:

use AlgoWeb\PODataLaravel\Models\MetadataTrait;
use Illuminate\Database\Eloquent\Model;

class userlocation extends Model
{
use MetadataTrait;

protected $fillable = array("WORKER_ID", "LOCATION_ID");
public $timestamps = false;

public function user(){
    return $this->belongsTo(remoteusers::class)->select(['id','userid as user_id']);
}

public function location(){
    return $this->belongsTo(location::class)->select(['id','code as location_id']);
}

}

how i can resolve this issue?

@dsv4890
Copy link

dsv4890 commented Jul 26, 2018

you need to write this line in place of use MetadataTrait;
Inside class userlocation

@CyberiaResurrection
Copy link
Contributor

CyberiaResurrection commented Jul 26, 2018

@yuri1994 , "userlocation" is the name of the entity type, while "userlocations" , plural, is the endpoint by default.

The base endpoint of odata.svc will give you a list of endpoints.

@dsv4890 , real life has caught up with me, I'm currently too busy to look at your issue. Thank you for jumping in on this one.

@yuri1994
Copy link
Author

yuri1994 commented Jul 26, 2018

@CyberiaResurrection, when i call base endpoint it return me
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <service xml:base="***/odata.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://www.w3.org/2007/app"> <workspace> <atom:title>Default</atom:title> </workspace> </service>

@yuri1994
Copy link
Author

i gone to debug and i found pice of code where checked for classes with MetadataTrait and then expect this class to be instance of Controller class, but in case the real instance is Model class.
Maybe i have missed some config but i don't know what exactly

@CyberiaResurrection
Copy link
Contributor

What's your metadata returning? odata.svc/$metadata

Have you hooked the service providers up?

@yuri1994
Copy link
Author

$metadata

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns="http://schemas.microsoft.com/ado/2009/11/edm" xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" Version="3.0"> <edmx:DataServices m:MaxDataServiceVersion="3.0" m:DataServiceVersion="3.0"> <Schema Namespace="Data"> <EntityContainer Name="Data" m:IsDefaultEntityContainer="true"/> </Schema> </edmx:DataServices> </edmx:Edmx>

i put the providers in config/app.php

    AlgoWeb\PODataLaravel\Providers\MetadataProvider::class,
    AlgoWeb\PODataLaravel\Providers\MetadataRouteProvider::class,
    AlgoWeb\PODataLaravel\Providers\QueryProvider::class,
    AlgoWeb\PODataLaravel\Providers\MetadataControllerProvider::class,

@c-harris
Copy link
Member

just to tick off the obvious things first. have you migrated? what database engine are you using?

@yuri1994
Copy link
Author

i use Firebird database engine

Migration file

`class Userlocation extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('userlocation',function (Blueprint $table){
$table->increments('id');
$table->integer('WORKER_ID')->unsigned();
$table->integer('location_id')->unsigned();
});

    Schema::table('userlocation', function($table) {
        $table->foreign('WORKER_ID')->references('id')->on('worker')->onDelete('cascade');
        $table->foreign('location_id')->references('id')->on('location')->onDelete('cascade');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('userlocation');
}

}`

@yuri1994
Copy link
Author

Which class in POData project get the name table and make request to database?

@c-harris
Copy link
Member

Podata makes no direct requests to the database, they are passed into Podata Laravel via the laravel query provider.

In POdata laravel MetadataProvider, is responsible to for fetching the information from models that have the trait.

I have not heard of Firebird but will look into it.

is there any chance you could dump out the variable passed to the unify method in MetadataProvider?

@yuri1994
Copy link
Author

yuri1994 commented Jul 26, 2018

@c-harris @CyberiaResurrection
The problem for me was the database engine. Now i change the code for Firebird engine and work well for GET requests. The new problem where is front to me is POST requests. How i can insert or update with POST request? Can anyone give me some example with POST?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants