GithubHelp home page GithubHelp logo

How do i manage references? about vasern HOT 8 CLOSED

vasern avatar vasern commented on May 18, 2024
How do i manage references?

from vasern.

Comments (8)

hieunc229 avatar hieunc229 commented on May 18, 2024

Hi @apppro123

  1. It will need 2 inserts, for Calendar and CalendarEvents. Besides, Vasern will automatically create an id (lowercase) field.
    (P/s: Custom id has not available yet, you won't need ID in your schema)

    Here is an example, with adding reference object:

    var insertedCalendars = Calendar.insert({ Title:"CalendarExample", Color:"#FFFFFF" });
    
    // Calendar.insert will return an array of objects will be inserted into database with generated id. 
    // For example:
    // insertedCalendars = [
    //     { id: 'a_random_unique_id', Title: "CalendarExample", Color:"#FFFFFF" }
    // ]
    
    var insertedEvents = CalendarEvents.insert({ 
        Title: "example",
        Start: startTime,
        End: endTime,
        Calendar: insertedCalendars[0] // or insertedCalendars[0].id - reference by `id` or actual object
    });
  2. Property with datetime will takes either a Date object or a time value in milliseconds. If you use Momentjs, I think you can use .valueOf() to get time in milliseconds. Though, datetime is not timezone aware.

from vasern.

apppro123 avatar apppro123 commented on May 18, 2024

You have used insertedCalendars[0] in insertedEvents under Calendar: Is it possible to insert objects? Or is it just possible to insert insertedCalendars[0].id?
And is every generated id unique for this element?

from vasern.

hieunc229 avatar hieunc229 commented on May 18, 2024

I'm a bit confuse about the question, pls let me know if my answer isn't what you are looking for.

  1. Yes, it's possible to insert an array of reference Calendar objects to CalendarEvents. But the schema needs to be changed to:

    var calendarEventSchema = {
       name: "CalendarEvents",
       props: {
          ...,
          Calendars: "[]#Calendar" // [] means list 
       }
    }

    Then you can pass the array of inserted objects like:

    var insertedEvents = CalendarEvents.insert({ 
        Title: "example",
        Start: startTime,
        End: endTime,
        Calendar: insertedCalendars
    });
  2. id generator was inspired with MongoDB ObjectID design, which is highly unique. Though, this element is not uniqued. Currently, to make sure an element is unique, you need to check in the database first (using filter). Sounds like a necessary feature for the upcoming version, I'll take note of this.

Just a head ups, data types will be updated in the next version, so "[]#Calendar" will be deprecated or invalid soon. Also, using lowercase for property name is more preferable.

from vasern.

apppro123 avatar apppro123 commented on May 18, 2024

Thank you first.
So is it possible to insert an object into an element of the db? I just need one Calendar for one event.

And ty for the tip with lowercase characters.

from vasern.

hieunc229 avatar hieunc229 commented on May 18, 2024

You're welcome. Yes, you can pass either a Calendar object or its id to CalendarEvents as

// it will automatically get and replace the `id` from `insertedCalendars[0]`
Calendar: insertedCalendars[0] 

from vasern.

apppro123 avatar apppro123 commented on May 18, 2024

Ok thanks!

from vasern.

hieunc229 avatar hieunc229 commented on May 18, 2024

No worries!

from vasern.

hieunc229 avatar hieunc229 commented on May 18, 2024

I will close this issue since it has been resolved. Also, feel free to reopen or create a new one again

from vasern.

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.