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

docs for findById a bit unclear around query options #3977

Closed
defunctzombie opened this issue Jun 19, 2015 · 14 comments
Closed

docs for findById a bit unclear around query options #3977

defunctzombie opened this issue Jun 19, 2015 · 14 comments
Labels
stale type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.

Comments

@defunctzombie
Copy link
Contributor

Is it allowed/supported to do

User.findById('user_id_string', { useMaster: true })

Or would I need to use the general case of findOne and specify my own where clause and useMaster within the options?

@mickhansen
Copy link
Contributor

findById takes all the same query options as all other calls, so useMaster, transaction, etc are supported.

@mickhansen
Copy link
Contributor

This might not be clear since we don't document all query options seperate for all methods, not sure if we should do this or just refer to query, @janmeier?

@mickhansen mickhansen added the type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference. label Jun 20, 2015
@mickhansen mickhansen reopened this Jun 20, 2015
@defunctzombie
Copy link
Contributor Author

Right, but it also accepts a string as the first argument. In that case if
I want to useMaster do I have a second options argument?

On Saturday, June 20, 2015, Mick Hansen notifications@github.com wrote:

Reopened #3977 #3977.


Reply to this email directly or view it on GitHub
#3977 (comment).

@mickhansen
Copy link
Contributor

Yes the signature for findById is (param, options)

@akotranza
Copy link

Please provide documentation for using findById. It has fewer google hits than... i dunno, fewer than anything.

@defunctzombie
Copy link
Contributor Author

@akotranza passing the uuid in string form works for me.

@mickhansen
Copy link
Contributor

@akotranza https://github.com/sequelize/sequelize/blob/master/lib/model.js#L1400 - What's your issue specifically?

Basically, findById takes a primary key value for a equality lookup as it's first argument, and all other finder options as it's second argument.

@akotranza
Copy link

Yes, I too have discovered that the uuid as string works. In general this project would benefit greatly from having at least one code example per method in the API. I appreciate the amount of detail in the User Guide section of the documentation, spreading even a 10th of that love over the API section would make using this library much less sticky.

@mickhansen
Copy link
Contributor

@akotranza Good suggestion, we might go about that :) Any assistance always welcome.

@stale stale bot added the stale label Jun 29, 2017
@stale
Copy link

stale bot commented Jun 29, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

@tsheaff
Copy link

tsheaff commented Oct 10, 2018

@mickhansen I know this is an old issue, but I'm wondering whether it's still the case that useMaster option works for non-.query() methods. For example modelInstance.findAll({ where: {...}, useMaster: true })

@mickhansen
Copy link
Contributor

@tsheaff IIRC all options from calls are passed to query() so yes it should work, mind you i haven't been involved with development of this project in a while

@dlarr
Copy link

dlarr commented Apr 8, 2019

@mickhansen :
1- Does this Master/slave feature work for MariaDB ?
2- Is this requiring some special Pool configuration ? Or somthing else ?

Many Thanks.

EDIT : After own research :
Answer to 1 : YES
Answer to 2 : Apparently it would work with like that :

	sequelize = new Sequelize(config.database, config.username, config.password, {
		replication: {
      			write: {
				host: AAA,
				port: BBB,
				username: CCC,
				password: DDD
			},
      			read: [{
				host: EEE,
				port: FFF,
				username: GGG,
				password: HHH
			}]
		},
		logging: config.logging,
		dialect: config.dialect,
		pool: config.pool
	});

Answer 3 : usage

models.Something.create({
                attr1: attr1Value,
                attr2: attr2Value
                attr3: attr3Value
}, {useMaster: true});

// or 
models.Something.findOne({
                where: {
                    attr1: attr1Value
                },
                useMaster, true
});

@yuriploc
Copy link

yuriploc commented Aug 3, 2019

@mickhansen :
1- Does this Master/slave feature work for MariaDB ?
2- Is this requiring some special Pool configuration ? Or somthing else ?

Many Thanks.

EDIT : After own research :
Answer to 1 : YES
Answer to 2 : Apparently it would work with like that :

	sequelize = new Sequelize(config.database, config.username, config.password, {
		replication: {
      			write: {
				host: AAA,
				port: BBB,
				username: CCC,
				password: DDD
			},
      			read: [{
				host: EEE,
				port: FFF,
				username: GGG,
				password: HHH
			}]
		},
		logging: config.logging,
		dialect: config.dialect,
		pool: config.pool
	});

Answer 3 : usage

models.Something.create({
                attr1: attr1Value,
                attr2: attr2Value
                attr3: attr3Value
}, {useMaster: true});

// or 
models.Something.findOne({
                where: {
                    attr1: attr1Value
                },
                useMaster, true
});

When doing something like

models.Something.findOne({
                where: {
                    attr1: attr1Value
                },
                useMaster, true
});

Do you have to use reload()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.
Projects
None yet
Development

No branches or pull requests

6 participants