Giter Site home page Giter Site logo

Comments (6)

denniseilander avatar denniseilander commented on September 24, 2024 2

@joedixon sorry for the late response, but your code is much cleaner and a better way to fix this problem. Thanks for fixing, did learn something today again.

from bear-sync.

denniseilander avatar denniseilander commented on September 24, 2024 1

@joedixon
I had the same issue. Just fixed it with a quick fix:

Create a new App\Tag model and overwrite the notes() method.
For example:

use BearSync\BearTag;

class Tag extends BearTag
{
    public function notes()
    {
        return $this->:belongsToMany(BearNote::class, 'Z_7TAGS', 'Z_14TAGS', 'Z_7NOTES');
    }
}

I think Bear uses different column/table names per version.

I'm trying to find a dynamic way to auto detect the column names. But not sure yet how to fix it without overriding the method

### UPDATE:
Using the above quick solution will break the connection of your own database, when you are using it.

This works fine:
App\BearNote.php

use BearSync\BearNote as Note;
use BearSync\BearTag as Tag;

class BearNote extends Note
{
    public function tags()
    {
        return $this->belongsToMany(Tag::class, 'Z_7TAGS', 'Z_7NOTES', 'Z_14TAGS');
    }
}

App\BearTag.php

use BearSync\BearNote as Note;
use BearSync\BearTag as Tag;

class BearTag extends Tag
{
    public function notes()
    {
        return $this->belongsToMany(Note::class, 'Z_7TAGS', 'Z_14TAGS', 'Z_7NOTES');
    }
}

from bear-sync.

joedixon avatar joedixon commented on September 24, 2024

@calebporzio, I'm digging some digging to see if I can get any more info from the database to make a dymanic solution.

Can you do me a favour and look at the values in the Z_ENT field of your ZSFNOTE and ZSFNOTETAG tables?

from bear-sync.

calebporzio avatar calebporzio commented on September 24, 2024

Sure thing! (thanks for looking into this!)

image
image

from bear-sync.

denniseilander avatar denniseilander commented on September 24, 2024

@joedixon @calebporzio I've tried to write a fix for this issue, with success...

I have extended the UsesBearsDatabaseConnection.php with 2 functions to retrieve the right table and columns

Then the function can be called in the BearNote and BearTag models with a regex to filter the right table/columnames.

For example, the tags() relation in the BearNote model has to be updated:

// Before
public function tags()
{
    return $this->belongsToMany(BearTag::class, 'Z_6TAGS', 'Z_6NOTES', 'Z_13TAGS');
}
// After
public function tags()
{
    return $this->belongsToMany(BearTag::class, static::getTagsTable(), static::getColumn('Z_[0-9]+NOTES'), static::getColumn('Z_[0-9]+TAGS'));
}

There is no configuration needed for the user.
I tested it by changing the column names of the tables and still able to retrieve the notes from Bear.

I make use of the SQLite3 class to select the raw data from the sqlite database. I couldn't retrieve that data using another way..

I can share the code with you/create a pull request if you want?
But I think you have to check the code and maybe refactor it.

Please let me know.

from bear-sync.

joedixon avatar joedixon commented on September 24, 2024

Hi @denniseilander, I put a PR up before seeing this comment. I used a similar approach, but got the data for generating the table and column names from a different place.

Let me know what you think #5

from bear-sync.

Related Issues (3)

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.