Skip to content

MySQL hasOne relation to Mongo #49

Closed
@tdicks

Description

@tdicks

I've never played with MongoDB before but this is really getting me into it. I'm using MySQL to store basic picture data such as filename, filesize etc, and MongoDB to store metadata which might be different for each picture (exif, ifd0) etc.

I've successfully got the MongoDB model set up and saving:

   $user = User::whereUsername('test_username')->first();
   $img = new Image();
   $img->filename = "hello.jpg";
   $img->save();

   $meta = new ImageMeta();
   $meta->exif_maker = "Canon";
   $meta->exif_model = "EOS 500D";
   $meta->save();

   $img->meta()->save($meta);

However when I try to get the metadata back from the image:

   echo $img->meta->exif_maker;

It returns NULL. Am I doing something wrong? If I look at the ImageMeta MongoDB model, I can see an image_id key which is populated with the image_id of the Image model.

Image relation:

$this->hasOne('ImageMeta');

ImageMeta relation:

$this->belongsTo('Image');

Image model table schema:

        Schema::create('images', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('filename');
            $table->integer('filesize');
            $table->string('hash');
            $table->string('hash_type');
            $table->integer('user_id');
            $table->timestamps();
        });

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions