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

First argument of `hasOne` must be a Model #598

Closed
ARMGAMES opened this Issue Dec 3, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@ARMGAMES

ARMGAMES commented Dec 3, 2016

What i do wrong?

adSource.js

import thinky from '../../thinky';

import User from '../user';
import Payment from './payment';

const { type, r } = thinky;
const adSource = thinky.createModel("adSource", {
    id: type.string(),
    userId: type.string(),
    paymentId: type.string(),
    source: type.string(),
    medium: type.string(),
    campaign: type.string(),
    content: type.number(),
    term: type.string(),
    createdAt: type.date().default(r.now())
});

adSource.hasOne(User, "affiliate", "userId", "id");
adSource.belongsTo(User, "user", "userId", "id");
adSource.belongsTo(Payment, "payment", "paymentId", "id");

export default adSource;

payment.js

import thinky from '../../thinky';

import User from '../user';
import adSource from './adSource';

const { type, r } = thinky;
const Payment = thinky.createModel("Payment", {
    id: type.string(),
    userId: type.string(),
    ammount: type.string(),
    createdAt: type.date().default(r.now())
});

Payment.hasOne(adSource, "adSource", "id", "paymentId");  <- this is error place, he don't like adSource
Payment.belongsTo(User, "user", "userId", "id");

export default Payment;

thinky.js

import thinky from 'thinky';
import {wrap, repeat} from 'lodash';

const Thinky = thinky({db: 'courses'});

/**
 * Console log queries executed
 * in development mode
 */
export function bindLogger() {

  if (process.env.NODE_ENV !== 'production') {

    Thinky.r._Term.prototype.run = wrap(Thinky.r._Term.prototype.run, function (func) {

      const queryToString = this.toString();
      const lines = 100;

      console.info(`START${repeat('-', lines)}`);
      console.info(queryToString);
      console.info(`END${repeat('-', lines + 2)}`);
      console.log('');

      var trailingArguments = [].slice.call(arguments, 1);
      return func.apply(this, trailingArguments);
    });
  }
}

export default Thinky;

Question

I am just started to use Thinky. Sorry for dumb question, but what i do wrong? Changed export to module.exports wont change anathing.

@neumino

This comment has been minimized.

Show comment
Hide comment
@neumino

neumino Dec 4, 2016

Owner

You have a circular dependency, and adSource is undefined in Payment.hasOne.
See http://thinky.io/documentation/architecture/

Owner

neumino commented Dec 4, 2016

You have a circular dependency, and adSource is undefined in Payment.hasOne.
See http://thinky.io/documentation/architecture/

@neumino neumino closed this Dec 4, 2016

@mmahalwy

This comment has been minimized.

Show comment
Hide comment
@mmahalwy

mmahalwy Apr 7, 2017

Have the same problem. How did you fix this?

mmahalwy commented Apr 7, 2017

Have the same problem. How did you fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment